mirror of
https://github.com/lubosz/overte.git
synced 2025-04-25 18:35:17 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into atmosphereBatchFix
This commit is contained in:
commit
af5a910f58
13 changed files with 663 additions and 311 deletions
|
@ -43,72 +43,90 @@ void BillboardOverlay::render(RenderArgs* args) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnable(GL_ALPHA_TEST);
|
glm::quat rotation;
|
||||||
glAlphaFunc(GL_GREATER, 0.5f);
|
if (_isFacingAvatar) {
|
||||||
|
// rotate about vertical to face the camera
|
||||||
|
rotation = Application::getInstance()->getCamera()->getRotation();
|
||||||
|
rotation *= glm::angleAxis(glm::pi<float>(), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
|
rotation *= getRotation();
|
||||||
|
} else {
|
||||||
|
rotation = getRotation();
|
||||||
|
}
|
||||||
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
float imageWidth = _texture->getWidth();
|
||||||
glDisable(GL_LIGHTING);
|
float imageHeight = _texture->getHeight();
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _texture->getID());
|
QRect fromImage;
|
||||||
|
if (_fromImage.isNull()) {
|
||||||
|
fromImage.setX(0);
|
||||||
|
fromImage.setY(0);
|
||||||
|
fromImage.setWidth(imageWidth);
|
||||||
|
fromImage.setHeight(imageHeight);
|
||||||
|
} else {
|
||||||
|
float scaleX = imageWidth / _texture->getOriginalWidth();
|
||||||
|
float scaleY = imageHeight / _texture->getOriginalHeight();
|
||||||
|
|
||||||
glPushMatrix(); {
|
fromImage.setX(scaleX * _fromImage.x());
|
||||||
glTranslatef(_position.x, _position.y, _position.z);
|
fromImage.setY(scaleY * _fromImage.y());
|
||||||
glm::quat rotation;
|
fromImage.setWidth(scaleX * _fromImage.width());
|
||||||
if (_isFacingAvatar) {
|
fromImage.setHeight(scaleY * _fromImage.height());
|
||||||
// rotate about vertical to face the camera
|
}
|
||||||
rotation = Application::getInstance()->getCamera()->getRotation();
|
|
||||||
rotation *= glm::angleAxis(glm::pi<float>(), glm::vec3(0.0f, 1.0f, 0.0f));
|
|
||||||
rotation *= getRotation();
|
|
||||||
} else {
|
|
||||||
rotation = getRotation();
|
|
||||||
}
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
glScalef(_scale, _scale, _scale);
|
|
||||||
|
|
||||||
const float MAX_COLOR = 255.0f;
|
float maxSize = glm::max(fromImage.width(), fromImage.height());
|
||||||
xColor color = getColor();
|
float x = fromImage.width() / (2.0f * maxSize);
|
||||||
float alpha = getAlpha();
|
float y = -fromImage.height() / (2.0f * maxSize);
|
||||||
|
|
||||||
float imageWidth = _texture->getWidth();
|
glm::vec2 topLeft(-x, -y);
|
||||||
float imageHeight = _texture->getHeight();
|
glm::vec2 bottomRight(x, y);
|
||||||
|
glm::vec2 texCoordTopLeft(fromImage.x() / imageWidth, fromImage.y() / imageHeight);
|
||||||
|
glm::vec2 texCoordBottomRight((fromImage.x() + fromImage.width()) / imageWidth,
|
||||||
|
(fromImage.y() + fromImage.height()) / imageHeight);
|
||||||
|
|
||||||
QRect fromImage;
|
const float MAX_COLOR = 255.0f;
|
||||||
if (_fromImage.isNull()) {
|
xColor color = getColor();
|
||||||
fromImage.setX(0);
|
float alpha = getAlpha();
|
||||||
fromImage.setY(0);
|
|
||||||
fromImage.setWidth(imageWidth);
|
|
||||||
fromImage.setHeight(imageHeight);
|
|
||||||
} else {
|
|
||||||
float scaleX = imageWidth / _texture->getOriginalWidth();
|
|
||||||
float scaleY = imageHeight / _texture->getOriginalHeight();
|
|
||||||
|
|
||||||
fromImage.setX(scaleX * _fromImage.x());
|
auto batch = args->_batch;
|
||||||
fromImage.setY(scaleY * _fromImage.y());
|
|
||||||
fromImage.setWidth(scaleX * _fromImage.width());
|
|
||||||
fromImage.setHeight(scaleY * _fromImage.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
float maxSize = glm::max(fromImage.width(), fromImage.height());
|
if (batch) {
|
||||||
float x = fromImage.width() / (2.0f * maxSize);
|
Transform transform;
|
||||||
float y = -fromImage.height() / (2.0f * maxSize);
|
transform.setTranslation(_position);
|
||||||
|
transform.setRotation(rotation);
|
||||||
|
transform.setScale(_scale);
|
||||||
|
|
||||||
glm::vec2 topLeft(-x, -y);
|
batch->setModelTransform(transform);
|
||||||
glm::vec2 bottomRight(x, y);
|
batch->setUniformTexture(0, _texture->getGPUTexture());
|
||||||
glm::vec2 texCoordTopLeft(fromImage.x() / imageWidth, fromImage.y() / imageHeight);
|
|
||||||
glm::vec2 texCoordBottomRight((fromImage.x() + fromImage.width()) / imageWidth,
|
DependencyManager::get<GeometryCache>()->renderQuad(*batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight,
|
||||||
(fromImage.y() + fromImage.height()) / imageHeight);
|
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight,
|
|
||||||
glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha));
|
glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha));
|
||||||
|
|
||||||
|
batch->setUniformTexture(0, args->_whiteTexture); // restore default white color after me
|
||||||
|
} else {
|
||||||
|
glEnable(GL_ALPHA_TEST);
|
||||||
|
glAlphaFunc(GL_GREATER, 0.5f);
|
||||||
|
|
||||||
} glPopMatrix();
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
glBindTexture(GL_TEXTURE_2D, _texture->getID());
|
||||||
glEnable(GL_LIGHTING);
|
|
||||||
glDisable(GL_ALPHA_TEST);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glPushMatrix(); {
|
||||||
|
glTranslatef(_position.x, _position.y, _position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
glScalef(_scale, _scale, _scale);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight,
|
||||||
|
glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha));
|
||||||
|
|
||||||
|
} glPopMatrix();
|
||||||
|
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glDisable(GL_ALPHA_TEST);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BillboardOverlay::setProperties(const QScriptValue &properties) {
|
void BillboardOverlay::setProperties(const QScriptValue &properties) {
|
||||||
|
|
|
@ -35,13 +35,6 @@ void Cube3DOverlay::render(RenderArgs* args) {
|
||||||
return; // do nothing if we're not visible
|
return; // do nothing if we're not visible
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float glowLevel = getGlowLevel();
|
|
||||||
Glower* glower = NULL;
|
|
||||||
if (glowLevel > 0.0f) {
|
|
||||||
glower = new Glower(glowLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
float alpha = getAlpha();
|
float alpha = getAlpha();
|
||||||
xColor color = getColor();
|
xColor color = getColor();
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
|
@ -49,91 +42,161 @@ void Cube3DOverlay::render(RenderArgs* args) {
|
||||||
|
|
||||||
//glDisable(GL_LIGHTING);
|
//glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
// TODO: handle registration point??
|
// TODO: handle registration point??
|
||||||
glm::vec3 position = getPosition();
|
glm::vec3 position = getPosition();
|
||||||
glm::vec3 center = getCenter();
|
glm::vec3 center = getCenter();
|
||||||
glm::vec3 dimensions = getDimensions();
|
glm::vec3 dimensions = getDimensions();
|
||||||
glm::quat rotation = getRotation();
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(position.x, position.y, position.z);
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
glPushMatrix();
|
|
||||||
glm::vec3 positionToCenter = center - position;
|
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
|
||||||
if (_isSolid) {
|
|
||||||
if (_borderSize > 0) {
|
|
||||||
// Draw a cube at a larger size behind the main cube, creating
|
|
||||||
// a border effect.
|
|
||||||
// Disable writing to the depth mask so that the "border" cube will not
|
|
||||||
// occlude the main cube. This means the border could be covered by
|
|
||||||
// overlays that are further back and drawn later, but this is good
|
|
||||||
// enough for the use-case.
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
glPushMatrix();
|
|
||||||
glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize);
|
|
||||||
|
|
||||||
if (_drawOnHUD) {
|
auto batch = args->_batch;
|
||||||
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
|
||||||
} else {
|
|
||||||
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
|
||||||
}
|
|
||||||
|
|
||||||
glPopMatrix();
|
if (batch) {
|
||||||
glDepthMask(GL_TRUE);
|
Transform transform;
|
||||||
}
|
transform.setTranslation(position);
|
||||||
|
transform.setRotation(rotation);
|
||||||
|
if (_isSolid) {
|
||||||
|
// if (_borderSize > 0) {
|
||||||
|
// // Draw a cube at a larger size behind the main cube, creating
|
||||||
|
// // a border effect.
|
||||||
|
// // Disable writing to the depth mask so that the "border" cube will not
|
||||||
|
// // occlude the main cube. This means the border could be covered by
|
||||||
|
// // overlays that are further back and drawn later, but this is good
|
||||||
|
// // enough for the use-case.
|
||||||
|
// transform.setScale(dimensions * _borderSize);
|
||||||
|
// batch->setModelTransform(transform);
|
||||||
|
// DependencyManager::get<GeometryCache>()->renderSolidCube(*batch, 1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
||||||
|
// }
|
||||||
|
|
||||||
|
transform.setScale(dimensions);
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(*batch, 1.0f, cubeColor);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
transform.setScale(1.0f);
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
glm::vec3 halfDimensions = dimensions / 2.0f;
|
||||||
|
glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
||||||
|
|
||||||
|
glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
||||||
|
|
||||||
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomLeftNear, bottomRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomRightNear, bottomRightFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomRightFar, bottomLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomLeftFar, bottomLeftNear, cubeColor);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(*batch, topLeftNear, topRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, topRightNear, topRightFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, topRightFar, topLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, topLeftFar, topLeftNear, cubeColor);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomLeftNear, topLeftNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomRightNear, topRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomLeftFar, topLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(*batch, bottomRightFar, topRightFar, cubeColor);
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
|
||||||
if (_drawOnHUD) {
|
|
||||||
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
|
|
||||||
} else {
|
|
||||||
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
} else {
|
} else {
|
||||||
glLineWidth(_lineWidth);
|
transform.setScale(dimensions);
|
||||||
|
batch->setModelTransform(transform);
|
||||||
if (getIsDashedLine()) {
|
DependencyManager::get<DeferredLightingEffect>()->renderWireCube(*batch, 1.0f, cubeColor);
|
||||||
glm::vec3 halfDimensions = dimensions / 2.0f;
|
|
||||||
glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
|
||||||
glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
|
||||||
glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
|
||||||
glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
|
||||||
|
|
||||||
glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
|
||||||
glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
|
||||||
glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
|
||||||
glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
|
||||||
|
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
|
||||||
|
|
||||||
geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomRightNear, bottomRightFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear, cubeColor);
|
|
||||||
|
|
||||||
geometryCache->renderDashedLine(topLeftNear, topRightNear, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(topRightNear, topRightFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(topRightFar, topLeftFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(topLeftFar, topLeftNear, cubeColor);
|
|
||||||
|
|
||||||
geometryCache->renderDashedLine(bottomLeftNear, topLeftNear, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomRightNear, topRightNear, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomLeftFar, topLeftFar, cubeColor);
|
|
||||||
geometryCache->renderDashedLine(bottomRightFar, topRightFar, cubeColor);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
|
||||||
DependencyManager::get<GeometryCache>()->renderWireCube(1.0f, cubeColor);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
}
|
||||||
glPopMatrix();
|
} else {
|
||||||
|
float glowLevel = getGlowLevel();
|
||||||
|
Glower* glower = NULL;
|
||||||
|
if (glowLevel > 0.0f) {
|
||||||
|
glower = new Glower(glowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
if (glower) {
|
glPushMatrix();
|
||||||
delete glower;
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
glPushMatrix();
|
||||||
|
glm::vec3 positionToCenter = center - position;
|
||||||
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
|
if (_isSolid) {
|
||||||
|
if (_borderSize > 0) {
|
||||||
|
// Draw a cube at a larger size behind the main cube, creating
|
||||||
|
// a border effect.
|
||||||
|
// Disable writing to the depth mask so that the "border" cube will not
|
||||||
|
// occlude the main cube. This means the border could be covered by
|
||||||
|
// overlays that are further back and drawn later, but this is good
|
||||||
|
// enough for the use-case.
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
glPushMatrix();
|
||||||
|
glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize);
|
||||||
|
|
||||||
|
if (_drawOnHUD) {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
||||||
|
} else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha));
|
||||||
|
}
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
|
if (_drawOnHUD) {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
|
||||||
|
} else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSolidCube(1.0f, cubeColor);
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
} else {
|
||||||
|
glLineWidth(_lineWidth);
|
||||||
|
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
glm::vec3 halfDimensions = dimensions / 2.0f;
|
||||||
|
glm::vec3 bottomLeftNear(-halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 bottomRightNear(halfDimensions.x, -halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 topLeftNear(-halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
||||||
|
glm::vec3 topRightNear(halfDimensions.x, halfDimensions.y, -halfDimensions.z);
|
||||||
|
|
||||||
|
glm::vec3 bottomLeftFar(-halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 bottomRightFar(halfDimensions.x, -halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 topLeftFar(-halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
||||||
|
glm::vec3 topRightFar(halfDimensions.x, halfDimensions.y, halfDimensions.z);
|
||||||
|
|
||||||
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomRightNear, bottomRightFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear, cubeColor);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(topLeftNear, topRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(topRightNear, topRightFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(topRightFar, topLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(topLeftFar, topLeftNear, cubeColor);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(bottomLeftNear, topLeftNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomRightNear, topRightNear, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomLeftFar, topLeftFar, cubeColor);
|
||||||
|
geometryCache->renderDashedLine(bottomRightFar, topRightFar, cubeColor);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderWireCube(1.0f, cubeColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
if (glower) {
|
||||||
|
delete glower;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,87 +36,128 @@ void Grid3DOverlay::render(RenderArgs* args) {
|
||||||
return; // do nothing if we're not visible
|
return; // do nothing if we're not visible
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_gridProgram.isLinked()) {
|
|
||||||
if (!_gridProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/grid.vert")) {
|
|
||||||
qDebug() << "Failed to compile: " + _gridProgram.log();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!_gridProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/grid.frag")) {
|
|
||||||
qDebug() << "Failed to compile: " + _gridProgram.log();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!_gridProgram.link()) {
|
|
||||||
qDebug() << "Failed to link: " + _gridProgram.log();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render code largely taken from MetavoxelEditor::render()
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
|
|
||||||
glDepthMask(GL_FALSE);
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
|
|
||||||
glm::quat rotation = getRotation();
|
|
||||||
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
|
|
||||||
glLineWidth(1.5f);
|
|
||||||
|
|
||||||
// center the grid around the camera position on the plane
|
|
||||||
glm::vec3 rotated = glm::inverse(rotation) * Application::getInstance()->getCamera()->getPosition();
|
|
||||||
float spacing = _minorGridWidth;
|
|
||||||
|
|
||||||
float alpha = getAlpha();
|
|
||||||
xColor color = getColor();
|
|
||||||
glm::vec3 position = getPosition();
|
|
||||||
|
|
||||||
const int MINOR_GRID_DIVISIONS = 200;
|
const int MINOR_GRID_DIVISIONS = 200;
|
||||||
const int MAJOR_GRID_DIVISIONS = 100;
|
const int MAJOR_GRID_DIVISIONS = 100;
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
|
|
||||||
|
// center the grid around the camera position on the plane
|
||||||
|
glm::vec3 rotated = glm::inverse(_rotation) * Application::getInstance()->getCamera()->getPosition();
|
||||||
|
|
||||||
|
float spacing = _minorGridWidth;
|
||||||
|
|
||||||
|
float alpha = getAlpha();
|
||||||
|
xColor color = getColor();
|
||||||
glm::vec4 gridColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
glm::vec4 gridColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||||
|
|
||||||
_gridProgram.bind();
|
auto batch = args->_batch;
|
||||||
|
|
||||||
// Minor grid
|
if (batch) {
|
||||||
glPushMatrix();
|
Transform transform;
|
||||||
{
|
transform.setRotation(_rotation);
|
||||||
glTranslatef(_minorGridWidth * (floorf(rotated.x / spacing) - MINOR_GRID_DIVISIONS / 2),
|
|
||||||
spacing * (floorf(rotated.y / spacing) - MINOR_GRID_DIVISIONS / 2), position.z);
|
|
||||||
|
|
||||||
float scale = MINOR_GRID_DIVISIONS * spacing;
|
|
||||||
glScalef(scale, scale, scale);
|
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderGrid(MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS, gridColor);
|
// Minor grid
|
||||||
|
{
|
||||||
|
batch->_glLineWidth(1.0f);
|
||||||
|
auto position = glm::vec3(_minorGridWidth * (floorf(rotated.x / spacing) - MINOR_GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floorf(rotated.y / spacing) - MINOR_GRID_DIVISIONS / 2),
|
||||||
|
_position.z);
|
||||||
|
float scale = MINOR_GRID_DIVISIONS * spacing;
|
||||||
|
|
||||||
|
transform.setTranslation(position);
|
||||||
|
transform.setScale(scale);
|
||||||
|
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderGrid(*batch, MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS, gridColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Major grid
|
||||||
|
{
|
||||||
|
batch->_glLineWidth(4.0f);
|
||||||
|
spacing *= _majorGridEvery;
|
||||||
|
auto position = glm::vec3(spacing * (floorf(rotated.x / spacing) - MAJOR_GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floorf(rotated.y / spacing) - MAJOR_GRID_DIVISIONS / 2),
|
||||||
|
_position.z);
|
||||||
|
float scale = MAJOR_GRID_DIVISIONS * spacing;
|
||||||
|
|
||||||
|
transform.setTranslation(position);
|
||||||
|
transform.setScale(scale);
|
||||||
|
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderGrid(*batch, MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS, gridColor);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!_gridProgram.isLinked()) {
|
||||||
|
if (!_gridProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/grid.vert")) {
|
||||||
|
qDebug() << "Failed to compile: " + _gridProgram.log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_gridProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/grid.frag")) {
|
||||||
|
qDebug() << "Failed to compile: " + _gridProgram.log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_gridProgram.link()) {
|
||||||
|
qDebug() << "Failed to link: " + _gridProgram.log();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render code largely taken from MetavoxelEditor::render()
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
|
||||||
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
|
||||||
|
glLineWidth(1.5f);
|
||||||
|
|
||||||
|
glm::vec3 position = getPosition();
|
||||||
|
|
||||||
|
_gridProgram.bind();
|
||||||
|
|
||||||
|
// Minor grid
|
||||||
|
glPushMatrix();
|
||||||
|
{
|
||||||
|
glTranslatef(_minorGridWidth * (floorf(rotated.x / spacing) - MINOR_GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floorf(rotated.y / spacing) - MINOR_GRID_DIVISIONS / 2), position.z);
|
||||||
|
|
||||||
|
float scale = MINOR_GRID_DIVISIONS * spacing;
|
||||||
|
glScalef(scale, scale, scale);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderGrid(MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS, gridColor);
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
// Major grid
|
||||||
|
glPushMatrix();
|
||||||
|
{
|
||||||
|
glLineWidth(4.0f);
|
||||||
|
spacing *= _majorGridEvery;
|
||||||
|
glTranslatef(spacing * (floorf(rotated.x / spacing) - MAJOR_GRID_DIVISIONS / 2),
|
||||||
|
spacing * (floorf(rotated.y / spacing) - MAJOR_GRID_DIVISIONS / 2), position.z);
|
||||||
|
|
||||||
|
float scale = MAJOR_GRID_DIVISIONS * spacing;
|
||||||
|
glScalef(scale, scale, scale);
|
||||||
|
|
||||||
|
DependencyManager::get<GeometryCache>()->renderGrid(MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS, gridColor);
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
_gridProgram.release();
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
}
|
}
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
// Major grid
|
|
||||||
glPushMatrix();
|
|
||||||
{
|
|
||||||
glLineWidth(4.0f);
|
|
||||||
spacing *= _majorGridEvery;
|
|
||||||
glTranslatef(spacing * (floorf(rotated.x / spacing) - MAJOR_GRID_DIVISIONS / 2),
|
|
||||||
spacing * (floorf(rotated.y / spacing) - MAJOR_GRID_DIVISIONS / 2), position.z);
|
|
||||||
|
|
||||||
float scale = MAJOR_GRID_DIVISIONS * spacing;
|
|
||||||
glScalef(scale, scale, scale);
|
|
||||||
|
|
||||||
DependencyManager::get<GeometryCache>()->renderGrid(MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS, gridColor);
|
|
||||||
}
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
_gridProgram.release();
|
|
||||||
|
|
||||||
glPopMatrix();
|
|
||||||
|
|
||||||
glEnable(GL_LIGHTING);
|
|
||||||
glDepthMask(GL_TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Grid3DOverlay::setProperties(const QScriptValue& properties) {
|
void Grid3DOverlay::setProperties(const QScriptValue& properties) {
|
||||||
|
|
|
@ -37,41 +37,57 @@ void Line3DOverlay::render(RenderArgs* args) {
|
||||||
return; // do nothing if we're not visible
|
return; // do nothing if we're not visible
|
||||||
}
|
}
|
||||||
|
|
||||||
float glowLevel = getGlowLevel();
|
|
||||||
Glower* glower = NULL;
|
|
||||||
if (glowLevel > 0.0f) {
|
|
||||||
glower = new Glower(glowLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
glLineWidth(_lineWidth);
|
|
||||||
|
|
||||||
float alpha = getAlpha();
|
float alpha = getAlpha();
|
||||||
xColor color = getColor();
|
xColor color = getColor();
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||||
|
|
||||||
glm::vec3 position = getPosition();
|
auto batch = args->_batch;
|
||||||
glm::quat rotation = getRotation();
|
|
||||||
|
|
||||||
glTranslatef(position.x, position.y, position.z);
|
if (batch) {
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
Transform transform;
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
transform.setTranslation(_position);
|
||||||
|
transform.setRotation(_rotation);
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
if (getIsDashedLine()) {
|
if (getIsDashedLine()) {
|
||||||
// TODO: add support for color to renderDashedLine()
|
// TODO: add support for color to renderDashedLine()
|
||||||
DependencyManager::get<GeometryCache>()->renderDashedLine(_position, _end, colorv4, _geometryCacheID);
|
DependencyManager::get<GeometryCache>()->renderDashedLine(*batch, _position, _end, colorv4, _geometryCacheID);
|
||||||
|
} else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderLine(*batch, _start, _end, colorv4, _geometryCacheID);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
DependencyManager::get<GeometryCache>()->renderLine(_start, _end, colorv4, _geometryCacheID);
|
float glowLevel = getGlowLevel();
|
||||||
}
|
Glower* glower = NULL;
|
||||||
glEnable(GL_LIGHTING);
|
if (glowLevel > 0.0f) {
|
||||||
|
glower = new Glower(glowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
if (glower) {
|
glDisable(GL_LIGHTING);
|
||||||
delete glower;
|
glLineWidth(_lineWidth);
|
||||||
|
|
||||||
|
glm::vec3 position = getPosition();
|
||||||
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
// TODO: add support for color to renderDashedLine()
|
||||||
|
DependencyManager::get<GeometryCache>()->renderDashedLine(_position, _end, colorv4, _geometryCacheID);
|
||||||
|
} else {
|
||||||
|
DependencyManager::get<GeometryCache>()->renderLine(_start, _end, colorv4, _geometryCacheID);
|
||||||
|
}
|
||||||
|
glEnable(GL_LIGHTING);
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
|
|
||||||
|
if (glower) {
|
||||||
|
delete glower;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,8 +66,8 @@ namespace render {
|
||||||
}
|
}
|
||||||
template <> void payloadRender(const Overlay::Pointer& overlay, RenderArgs* args) {
|
template <> void payloadRender(const Overlay::Pointer& overlay, RenderArgs* args) {
|
||||||
if (args) {
|
if (args) {
|
||||||
glPushMatrix();
|
|
||||||
if (overlay->getAnchor() == Overlay::MY_AVATAR) {
|
if (overlay->getAnchor() == Overlay::MY_AVATAR) {
|
||||||
|
glPushMatrix();
|
||||||
MyAvatar* avatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
MyAvatar* avatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
glm::quat myAvatarRotation = avatar->getOrientation();
|
glm::quat myAvatarRotation = avatar->getOrientation();
|
||||||
glm::vec3 myAvatarPosition = avatar->getPosition();
|
glm::vec3 myAvatarPosition = avatar->getPosition();
|
||||||
|
@ -78,9 +78,11 @@ namespace render {
|
||||||
glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z);
|
glTranslatef(myAvatarPosition.x, myAvatarPosition.y, myAvatarPosition.z);
|
||||||
glRotatef(angle, axis.x, axis.y, axis.z);
|
glRotatef(angle, axis.x, axis.y, axis.z);
|
||||||
glScalef(myAvatarScale, myAvatarScale, myAvatarScale);
|
glScalef(myAvatarScale, myAvatarScale, myAvatarScale);
|
||||||
|
overlay->render(args);
|
||||||
|
glPopMatrix();
|
||||||
|
} else {
|
||||||
|
overlay->render(args);
|
||||||
}
|
}
|
||||||
overlay->render(args);
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,74 +41,116 @@ void Rectangle3DOverlay::render(RenderArgs* args) {
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
|
||||||
|
|
||||||
glm::vec3 position = getPosition();
|
glm::vec3 position = getPosition();
|
||||||
glm::vec3 center = getCenter();
|
glm::vec3 center = getCenter();
|
||||||
glm::vec2 dimensions = getDimensions();
|
glm::vec2 dimensions = getDimensions();
|
||||||
glm::vec2 halfDimensions = dimensions * 0.5f;
|
glm::vec2 halfDimensions = dimensions * 0.5f;
|
||||||
glm::quat rotation = getRotation();
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
float glowLevel = getGlowLevel();
|
auto batch = args->_batch;
|
||||||
Glower* glower = NULL;
|
|
||||||
if (glowLevel > 0.0f) {
|
|
||||||
glower = new Glower(glowLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
glPushMatrix();
|
if (batch) {
|
||||||
glTranslatef(position.x, position.y, position.z);
|
Transform transform;
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
transform.setTranslation(position);
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
transform.setRotation(rotation);
|
||||||
glPushMatrix();
|
|
||||||
glm::vec3 positionToCenter = center - position;
|
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
|
||||||
//glScalef(dimensions.x, dimensions.y, 1.0f);
|
|
||||||
|
|
||||||
glLineWidth(_lineWidth);
|
batch->setModelTransform(transform);
|
||||||
|
|
||||||
|
if (getIsSolid()) {
|
||||||
|
glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderQuad(*batch, topLeft, bottomRight, rectangleColor);
|
||||||
|
} else {
|
||||||
auto geometryCache = DependencyManager::get<GeometryCache>();
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
|
||||||
// for our overlay, is solid means we draw a solid "filled" rectangle otherwise we just draw a border line...
|
geometryCache->renderDashedLine(*batch, point1, point2, rectangleColor);
|
||||||
if (getIsSolid()) {
|
geometryCache->renderDashedLine(*batch, point2, point3, rectangleColor);
|
||||||
glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
geometryCache->renderDashedLine(*batch, point3, point4, rectangleColor);
|
||||||
glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f);
|
geometryCache->renderDashedLine(*batch, point4, point1, rectangleColor);
|
||||||
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, rectangleColor);
|
|
||||||
} else {
|
} else {
|
||||||
if (getIsDashedLine()) {
|
if (halfDimensions != _previousHalfDimensions) {
|
||||||
|
QVector<glm::vec3> border;
|
||||||
|
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
geometryCache->updateVertices(_geometryCacheID, border, rectangleColor);
|
||||||
|
|
||||||
glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
_previousHalfDimensions = halfDimensions;
|
||||||
glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f);
|
|
||||||
glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f);
|
|
||||||
glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f);
|
|
||||||
|
|
||||||
geometryCache->renderDashedLine(point1, point2, rectangleColor);
|
|
||||||
geometryCache->renderDashedLine(point2, point3, rectangleColor);
|
|
||||||
geometryCache->renderDashedLine(point3, point4, rectangleColor);
|
|
||||||
geometryCache->renderDashedLine(point4, point1, rectangleColor);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (halfDimensions != _previousHalfDimensions) {
|
|
||||||
QVector<glm::vec3> border;
|
|
||||||
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
|
||||||
border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f);
|
|
||||||
border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f);
|
|
||||||
border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f);
|
|
||||||
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
|
||||||
geometryCache->updateVertices(_geometryCacheID, border, rectangleColor);
|
|
||||||
|
|
||||||
_previousHalfDimensions = halfDimensions;
|
|
||||||
|
|
||||||
}
|
|
||||||
geometryCache->renderVertices(gpu::LINE_STRIP, _geometryCacheID);
|
|
||||||
}
|
}
|
||||||
|
geometryCache->renderVertices(*batch, gpu::LINE_STRIP, _geometryCacheID);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
float glowLevel = getGlowLevel();
|
||||||
|
Glower* glower = NULL;
|
||||||
|
if (glowLevel > 0.0f) {
|
||||||
|
glower = new Glower(glowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
glPushMatrix();
|
||||||
|
glTranslatef(position.x, position.y, position.z);
|
||||||
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
|
glPushMatrix();
|
||||||
|
glm::vec3 positionToCenter = center - position;
|
||||||
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
|
//glScalef(dimensions.x, dimensions.y, 1.0f);
|
||||||
|
|
||||||
|
glLineWidth(_lineWidth);
|
||||||
|
|
||||||
|
auto geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
|
||||||
|
// for our overlay, is solid means we draw a solid "filled" rectangle otherwise we just draw a border line...
|
||||||
|
if (getIsSolid()) {
|
||||||
|
glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderQuad(topLeft, bottomRight, rectangleColor);
|
||||||
|
} else {
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
|
||||||
|
glm::vec3 point1(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point2(halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point3(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
glm::vec3 point4(-halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
|
||||||
|
geometryCache->renderDashedLine(point1, point2, rectangleColor);
|
||||||
|
geometryCache->renderDashedLine(point2, point3, rectangleColor);
|
||||||
|
geometryCache->renderDashedLine(point3, point4, rectangleColor);
|
||||||
|
geometryCache->renderDashedLine(point4, point1, rectangleColor);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (halfDimensions != _previousHalfDimensions) {
|
||||||
|
QVector<glm::vec3> border;
|
||||||
|
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(-halfDimensions.x, halfDimensions.y, 0.0f);
|
||||||
|
border << glm::vec3(-halfDimensions.x, -halfDimensions.y, 0.0f);
|
||||||
|
geometryCache->updateVertices(_geometryCacheID, border, rectangleColor);
|
||||||
|
|
||||||
|
_previousHalfDimensions = halfDimensions;
|
||||||
|
|
||||||
|
}
|
||||||
|
geometryCache->renderVertices(gpu::LINE_STRIP, _geometryCacheID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopMatrix();
|
|
||||||
|
if (glower) {
|
||||||
if (glower) {
|
delete glower;
|
||||||
delete glower;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,33 +39,45 @@ void Sphere3DOverlay::render(RenderArgs* args) {
|
||||||
const float MAX_COLOR = 255.0f;
|
const float MAX_COLOR = 255.0f;
|
||||||
glm::vec4 sphereColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
glm::vec4 sphereColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
auto batch = args->_batch;
|
||||||
|
|
||||||
glm::vec3 position = getPosition();
|
|
||||||
glm::vec3 center = getCenter();
|
|
||||||
glm::vec3 dimensions = getDimensions();
|
|
||||||
glm::quat rotation = getRotation();
|
|
||||||
|
|
||||||
float glowLevel = getGlowLevel();
|
if (batch) {
|
||||||
Glower* glower = NULL;
|
Transform transform;
|
||||||
if (glowLevel > 0.0f) {
|
transform.setTranslation(_position);
|
||||||
glower = new Glower(glowLevel);
|
transform.setRotation(_rotation);
|
||||||
}
|
transform.setScale(_dimensions);
|
||||||
|
|
||||||
|
batch->setModelTransform(transform);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSphere(*batch, 1.0f, SLICES, SLICES, sphereColor, _isSolid);
|
||||||
|
} else {
|
||||||
|
glDisable(GL_LIGHTING);
|
||||||
|
|
||||||
|
glm::vec3 position = getPosition();
|
||||||
|
glm::vec3 center = getCenter();
|
||||||
|
glm::vec3 dimensions = getDimensions();
|
||||||
|
glm::quat rotation = getRotation();
|
||||||
|
|
||||||
|
float glowLevel = getGlowLevel();
|
||||||
|
Glower* glower = NULL;
|
||||||
|
if (glowLevel > 0.0f) {
|
||||||
|
glower = new Glower(glowLevel);
|
||||||
|
}
|
||||||
|
|
||||||
glPushMatrix();
|
|
||||||
glTranslatef(position.x, position.y, position.z);
|
|
||||||
glm::vec3 axis = glm::axis(rotation);
|
|
||||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glm::vec3 positionToCenter = center - position;
|
glTranslatef(position.x, position.y, position.z);
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
glm::vec3 axis = glm::axis(rotation);
|
||||||
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||||
DependencyManager::get<GeometryCache>()->renderSphere(1.0f, SLICES, SLICES, sphereColor, _isSolid);
|
glPushMatrix();
|
||||||
|
glm::vec3 positionToCenter = center - position;
|
||||||
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
|
glScalef(dimensions.x, dimensions.y, dimensions.z);
|
||||||
|
DependencyManager::get<GeometryCache>()->renderSphere(1.0f, SLICES, SLICES, sphereColor, _isSolid);
|
||||||
|
glPopMatrix();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopMatrix();
|
|
||||||
|
if (glower) {
|
||||||
if (glower) {
|
delete glower;
|
||||||
delete glower;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,11 @@ void makeBindings(GLBackend::GLShader* shader) {
|
||||||
if (loc >= 0) {
|
if (loc >= 0) {
|
||||||
glBindAttribLocation(glprogram, gpu::Stream::TEXCOORD, "texcoord");
|
glBindAttribLocation(glprogram, gpu::Stream::TEXCOORD, "texcoord");
|
||||||
}
|
}
|
||||||
|
loc = glGetAttribLocation(glprogram, "attribTexcoord");
|
||||||
|
if (loc >= 0) {
|
||||||
|
glBindAttribLocation(glprogram, gpu::Stream::TEXCOORD, "attribTexcoord");
|
||||||
|
}
|
||||||
|
|
||||||
loc = glGetAttribLocation(glprogram, "tangent");
|
loc = glGetAttribLocation(glprogram, "tangent");
|
||||||
if (loc >= 0) {
|
if (loc >= 0) {
|
||||||
glBindAttribLocation(glprogram, gpu::Stream::TANGENT, "tangent");
|
glBindAttribLocation(glprogram, gpu::Stream::TANGENT, "tangent");
|
||||||
|
|
|
@ -15,9 +15,12 @@
|
||||||
#include "DeferredLightingEffect.h"
|
#include "DeferredLightingEffect.h"
|
||||||
#include "ViewFrustum.h"
|
#include "ViewFrustum.h"
|
||||||
#include "RenderArgs.h"
|
#include "RenderArgs.h"
|
||||||
|
#include "TextureCache.h"
|
||||||
|
|
||||||
#include <PerfStat.h>
|
#include <PerfStat.h>
|
||||||
|
|
||||||
|
#include "overlay3D_vert.h"
|
||||||
|
#include "overlay3D_frag.h"
|
||||||
|
|
||||||
using namespace render;
|
using namespace render;
|
||||||
|
|
||||||
|
@ -50,7 +53,7 @@ RenderDeferredTask::RenderDeferredTask() : Task() {
|
||||||
_jobs.push_back(Job(RenderDeferred()));
|
_jobs.push_back(Job(RenderDeferred()));
|
||||||
_jobs.push_back(Job(ResolveDeferred()));
|
_jobs.push_back(Job(ResolveDeferred()));
|
||||||
_jobs.push_back(Job(DrawTransparentDeferred()));
|
_jobs.push_back(Job(DrawTransparentDeferred()));
|
||||||
_jobs.push_back(Job(DrawPostLayered()));
|
_jobs.push_back(Job(DrawOverlay3D()));
|
||||||
_jobs.push_back(Job(ResetGLState()));
|
_jobs.push_back(Job(ResetGLState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,10 +228,76 @@ template <> void render::jobRun(const DrawTransparentDeferred& job, const SceneC
|
||||||
|
|
||||||
renderItems(sceneContext, renderContext, renderedItems, renderContext->_maxDrawnTransparentItems);
|
renderItems(sceneContext, renderContext, renderedItems, renderContext->_maxDrawnTransparentItems);
|
||||||
|
|
||||||
|
// Before rendering the batch make sure we re in sync with gl state
|
||||||
|
args->_context->syncCache();
|
||||||
args->_context->render((*args->_batch));
|
args->_context->render((*args->_batch));
|
||||||
args->_batch = nullptr;
|
args->_batch = nullptr;
|
||||||
|
|
||||||
// reset blend function to standard...
|
// reset blend function to standard...
|
||||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
|
// glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const gpu::PipelinePointer& DrawOverlay3D::getOpaquePipeline() const {
|
||||||
|
if (!_opaquePipeline) {
|
||||||
|
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(overlay3D_vert)));
|
||||||
|
auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(overlay3D_frag)));
|
||||||
|
|
||||||
|
auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps));
|
||||||
|
|
||||||
|
auto state = gpu::StatePointer(new gpu::State());
|
||||||
|
state->setDepthTest(true, true, gpu::LESS_EQUAL);
|
||||||
|
|
||||||
|
_opaquePipeline.reset(gpu::Pipeline::create(program, state));
|
||||||
|
}
|
||||||
|
return _opaquePipeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> void render::jobRun(const DrawOverlay3D& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||||
|
PerformanceTimer perfTimer("DrawOverlay3D");
|
||||||
|
assert(renderContext->args);
|
||||||
|
assert(renderContext->args->_viewFrustum);
|
||||||
|
|
||||||
|
// render backgrounds
|
||||||
|
auto& scene = sceneContext->_scene;
|
||||||
|
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::opaqueShape().withLayered());
|
||||||
|
|
||||||
|
|
||||||
|
ItemIDsBounds inItems;
|
||||||
|
inItems.reserve(items.size());
|
||||||
|
for (auto id : items) {
|
||||||
|
auto& item = scene->getItem(id);
|
||||||
|
if (item.getKey().isVisible() && (item.getLayer() == 1)) {
|
||||||
|
inItems.emplace_back(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RenderArgs* args = renderContext->args;
|
||||||
|
gpu::Batch batch;
|
||||||
|
args->_batch = &batch;
|
||||||
|
args->_whiteTexture = DependencyManager::get<TextureCache>()->getWhiteTexture();
|
||||||
|
|
||||||
|
|
||||||
|
glm::mat4 projMat;
|
||||||
|
Transform viewMat;
|
||||||
|
args->_viewFrustum->evalProjectionMatrix(projMat);
|
||||||
|
args->_viewFrustum->evalViewTransform(viewMat);
|
||||||
|
if (args->_renderMode == RenderArgs::MIRROR_RENDER_MODE) {
|
||||||
|
viewMat.postScale(glm::vec3(-1.0f, 1.0f, 1.0f));
|
||||||
|
}
|
||||||
|
batch.setProjectionTransform(projMat);
|
||||||
|
batch.setViewTransform(viewMat);
|
||||||
|
batch.setPipeline(job.getOpaquePipeline());
|
||||||
|
batch.setUniformTexture(0, args->_whiteTexture);
|
||||||
|
|
||||||
|
if (!inItems.empty()) {
|
||||||
|
batch.clearFramebuffer(gpu::Framebuffer::BUFFER_DEPTH, glm::vec4(), 1.f, 0);
|
||||||
|
renderItems(sceneContext, renderContext, inItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Before rendering the batch make sure we re in sync with gl state
|
||||||
|
args->_context->syncCache();
|
||||||
|
args->_context->render((*args->_batch));
|
||||||
|
args->_batch = nullptr;
|
||||||
|
args->_whiteTexture.reset();
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include "render/DrawTask.h"
|
#include "render/DrawTask.h"
|
||||||
|
|
||||||
|
#include "gpu/Pipeline.h"
|
||||||
|
|
||||||
class PrepareDeferred {
|
class PrepareDeferred {
|
||||||
public:
|
public:
|
||||||
};
|
};
|
||||||
|
@ -50,6 +52,15 @@ namespace render {
|
||||||
template <> void jobRun(const DrawTransparentDeferred& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
template <> void jobRun(const DrawTransparentDeferred& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DrawOverlay3D {
|
||||||
|
mutable gpu::PipelinePointer _opaquePipeline; //lazy evaluation hence mutable
|
||||||
|
public:
|
||||||
|
const gpu::PipelinePointer& getOpaquePipeline() const;
|
||||||
|
};
|
||||||
|
namespace render {
|
||||||
|
template <> void jobRun(const DrawOverlay3D& job, const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext);
|
||||||
|
}
|
||||||
|
|
||||||
class RenderDeferredTask : public render::Task {
|
class RenderDeferredTask : public render::Task {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
29
libraries/render-utils/src/overlay3D.slf
Normal file
29
libraries/render-utils/src/overlay3D.slf
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<@include gpu/Config.slh@>
|
||||||
|
<$VERSION_HEADER$>
|
||||||
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
|
// model.frag
|
||||||
|
// fragment shader
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 6/16/15.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
uniform sampler2D diffuseMap;
|
||||||
|
|
||||||
|
varying vec2 varTexcoord;
|
||||||
|
|
||||||
|
varying vec3 varEyeNormal;
|
||||||
|
|
||||||
|
varying vec4 varColor;
|
||||||
|
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
vec4 diffuse = texture2D(diffuseMap, varTexcoord.st);
|
||||||
|
if (diffuse.a < 0.5) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
gl_FragColor = vec4(varColor * diffuse);
|
||||||
|
}
|
40
libraries/render-utils/src/overlay3D.slv
Normal file
40
libraries/render-utils/src/overlay3D.slv
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
<@include gpu/Config.slh@>
|
||||||
|
<$VERSION_HEADER$>
|
||||||
|
// Generated on <$_SCRIBE_DATE$>
|
||||||
|
// overlay3D.slv
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 6/16/15.
|
||||||
|
// Copyright 2015 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
<@include gpu/Transform.slh@>
|
||||||
|
|
||||||
|
<$declareStandardTransform()$>
|
||||||
|
|
||||||
|
//attribute vec2 texcoord;
|
||||||
|
|
||||||
|
varying vec2 varTexcoord;
|
||||||
|
|
||||||
|
// interpolated eye position
|
||||||
|
varying vec4 varEyePosition;
|
||||||
|
|
||||||
|
// the interpolated normal
|
||||||
|
varying vec3 varEyeNormal;
|
||||||
|
|
||||||
|
varying vec4 varColor;
|
||||||
|
|
||||||
|
void main(void) {
|
||||||
|
varTexcoord = gl_MultiTexCoord0.xy;
|
||||||
|
|
||||||
|
// pass along the color
|
||||||
|
varColor = gl_Color;
|
||||||
|
|
||||||
|
// standard transform
|
||||||
|
TransformCamera cam = getTransformCamera();
|
||||||
|
TransformObject obj = getTransformObject();
|
||||||
|
<$transformModelToEyeAndClipPos(cam, obj, gl_Vertex, varEyePosition, gl_Position)$>
|
||||||
|
<$transformModelToEyeDir(cam, obj, gl_Normal, varEyeNormal.xyz)$>
|
||||||
|
}
|
|
@ -13,6 +13,8 @@
|
||||||
#define hifi_RenderArgs_h
|
#define hifi_RenderArgs_h
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
class AABox;
|
class AABox;
|
||||||
class OctreeRenderer;
|
class OctreeRenderer;
|
||||||
|
@ -20,6 +22,7 @@ class ViewFrustum;
|
||||||
namespace gpu {
|
namespace gpu {
|
||||||
class Batch;
|
class Batch;
|
||||||
class Context;
|
class Context;
|
||||||
|
class Texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
class RenderDetails {
|
class RenderDetails {
|
||||||
|
@ -109,6 +112,8 @@ public:
|
||||||
gpu::Batch* _batch = nullptr;
|
gpu::Batch* _batch = nullptr;
|
||||||
ShoudRenderFunctor _shouldRender;
|
ShoudRenderFunctor _shouldRender;
|
||||||
|
|
||||||
|
std::shared_ptr<gpu::Texture> _whiteTexture;
|
||||||
|
|
||||||
RenderDetails _details;
|
RenderDetails _details;
|
||||||
|
|
||||||
float _alphaThreshold = 0.5f;
|
float _alphaThreshold = 0.5f;
|
||||||
|
|
Loading…
Reference in a new issue