Merge remote-tracking branch 'upstream/master' into HEAD

This commit is contained in:
Brad Davis 2015-10-19 09:59:03 -07:00
commit 1de811c754
19 changed files with 2727 additions and 2702 deletions

25
.gitattributes vendored Normal file
View file

@ -0,0 +1,25 @@
*.cpp text
*.c text
*.h text
*.qml text
*.js text
*.json text
*.slv text
*.slf text
*.slh text
*.vert text
*.frag text
*.fst text
*.ini text
*.html text
*.ts text
*.txt text
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.wav binary
*.fbx text
*.dds text
*.svg text
*.ttf text

File diff suppressed because it is too large Load diff

View file

@ -231,8 +231,8 @@ const gpu::PipelinePointer& DrawOverlay3D::getOpaquePipeline() {
auto state = std::make_shared<gpu::State>(); auto state = std::make_shared<gpu::State>();
state->setDepthTest(false); state->setDepthTest(false);
// additive blending // additive blending
state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE); state->setBlendFunction(true, gpu::State::ONE, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
_opaquePipeline.reset(gpu::Pipeline::create(program, state)); _opaquePipeline.reset(gpu::Pipeline::create(program, state));
} }
@ -336,7 +336,7 @@ void DrawStencilDeferred::run(const SceneContextPointer& sceneContext, const Ren
batch.setPipeline(getOpaquePipeline()); batch.setPipeline(getOpaquePipeline());
batch.draw(gpu::TRIANGLE_STRIP, 4); batch.draw(gpu::TRIANGLE_STRIP, 4);
batch.setResourceTexture(0, nullptr); batch.setResourceTexture(0, nullptr);
}); });

View file

@ -1,70 +1,70 @@
<! <!
// Skinning.slh // Skinning.slh
// libraries/render-utils/src // libraries/render-utils/src
// //
// Created by Sam Gateau on 10/5/15. // Created by Sam Gateau on 10/5/15.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
!> !>
<@if not SKINNING_SLH@> <@if not SKINNING_SLH@>
<@def SKINNING_SLH@> <@def SKINNING_SLH@>
const int MAX_TEXCOORDS = 2; const int MAX_TEXCOORDS = 2;
const int MAX_CLUSTERS = 128; const int MAX_CLUSTERS = 128;
const int INDICES_PER_VERTEX = 4; const int INDICES_PER_VERTEX = 4;
layout(std140) uniform skinClusterBuffer { layout(std140) uniform skinClusterBuffer {
mat4 clusterMatrices[MAX_CLUSTERS]; mat4 clusterMatrices[MAX_CLUSTERS];
}; };
void skinPosition(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPosition, out vec4 skinnedPosition) { void skinPosition(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPosition, out vec4 skinnedPosition) {
vec4 newPosition = vec4(0.0, 0.0, 0.0, 0.0); vec4 newPosition = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < INDICES_PER_VERTEX; i++) { for (int i = 0; i < INDICES_PER_VERTEX; i++) {
mat4 clusterMatrix = clusterMatrices[int(skinClusterIndex[i])]; mat4 clusterMatrix = clusterMatrices[int(skinClusterIndex[i])];
float clusterWeight = skinClusterWeight[i]; float clusterWeight = skinClusterWeight[i];
newPosition += clusterMatrix * inPosition * clusterWeight; newPosition += clusterMatrix * inPosition * clusterWeight;
} }
skinnedPosition = newPosition; skinnedPosition = newPosition;
} }
void skinPositionNormal(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPosition, vec3 inNormal, void skinPositionNormal(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPosition, vec3 inNormal,
out vec4 skinnedPosition, out vec3 skinnedNormal) { out vec4 skinnedPosition, out vec3 skinnedNormal) {
vec4 newPosition = vec4(0.0, 0.0, 0.0, 0.0); vec4 newPosition = vec4(0.0, 0.0, 0.0, 0.0);
vec4 newNormal = vec4(0.0, 0.0, 0.0, 0.0); vec4 newNormal = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < INDICES_PER_VERTEX; i++) { for (int i = 0; i < INDICES_PER_VERTEX; i++) {
mat4 clusterMatrix = clusterMatrices[int(skinClusterIndex[i])]; mat4 clusterMatrix = clusterMatrices[int(skinClusterIndex[i])];
float clusterWeight = skinClusterWeight[i]; float clusterWeight = skinClusterWeight[i];
newPosition += clusterMatrix * inPosition * clusterWeight; newPosition += clusterMatrix * inPosition * clusterWeight;
newNormal += clusterMatrix * vec4(inNormal.xyz, 0.0) * clusterWeight; newNormal += clusterMatrix * vec4(inNormal.xyz, 0.0) * clusterWeight;
} }
skinnedPosition = newPosition; skinnedPosition = newPosition;
skinnedNormal = newNormal.xyz; skinnedNormal = newNormal.xyz;
} }
void skinPositionNormalTangent(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPosition, vec3 inNormal, vec3 inTangent, void skinPositionNormalTangent(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPosition, vec3 inNormal, vec3 inTangent,
out vec4 skinnedPosition, out vec3 skinnedNormal, out vec3 skinnedTangent) { out vec4 skinnedPosition, out vec3 skinnedNormal, out vec3 skinnedTangent) {
vec4 newPosition = vec4(0.0, 0.0, 0.0, 0.0); vec4 newPosition = vec4(0.0, 0.0, 0.0, 0.0);
vec4 newNormal = vec4(0.0, 0.0, 0.0, 0.0); vec4 newNormal = vec4(0.0, 0.0, 0.0, 0.0);
vec4 newTangent = vec4(0.0, 0.0, 0.0, 0.0); vec4 newTangent = vec4(0.0, 0.0, 0.0, 0.0);
for (int i = 0; i < INDICES_PER_VERTEX; i++) { for (int i = 0; i < INDICES_PER_VERTEX; i++) {
mat4 clusterMatrix = clusterMatrices[int(skinClusterIndex[i])]; mat4 clusterMatrix = clusterMatrices[int(skinClusterIndex[i])];
float clusterWeight = skinClusterWeight[i]; float clusterWeight = skinClusterWeight[i];
newPosition += clusterMatrix * inPosition * clusterWeight; newPosition += clusterMatrix * inPosition * clusterWeight;
newNormal += clusterMatrix * vec4(inNormal.xyz, 0.0) * clusterWeight; newNormal += clusterMatrix * vec4(inNormal.xyz, 0.0) * clusterWeight;
newTangent += clusterMatrix * vec4(inTangent.xyz, 0.0) * clusterWeight; newTangent += clusterMatrix * vec4(inTangent.xyz, 0.0) * clusterWeight;
} }
skinnedPosition = newPosition; skinnedPosition = newPosition;
skinnedNormal = newNormal.xyz; skinnedNormal = newNormal.xyz;
skinnedTangent = newTangent.xyz; skinnedTangent = newTangent.xyz;
} }
<@endif@> <@endif@>

View file

@ -20,7 +20,7 @@
<$declareEvalAmbientSphereGlobalColor()$> <$declareEvalAmbientSphereGlobalColor()$>
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0; in vec2 _texCoord0;
out vec4 _fragColor; out vec4 _fragColor;

View file

@ -21,7 +21,7 @@
<$declareEvalAmbientGlobalColor()$> <$declareEvalAmbientGlobalColor()$>
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0; in vec2 _texCoord0;
out vec4 _fragColor; out vec4 _fragColor;

View file

@ -21,7 +21,7 @@
<$declareEvalSkyboxGlobalColor()$> <$declareEvalSkyboxGlobalColor()$>
// Everything about shadow // Everything about shadow
<@include Shadow.slh@> <@include Shadow.slh@>
in vec2 _texCoord0; in vec2 _texCoord0;
out vec4 _fragColor; out vec4 _fragColor;

View file

@ -1,44 +1,44 @@
<@include gpu/Config.slh@> <@include gpu/Config.slh@>
<$VERSION_HEADER$> <$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$> // Generated on <$_SCRIBE_DATE$>
// //
// model_normal_map.vert // model_normal_map.vert
// vertex shader // vertex shader
// //
// Created by Andrzej Kapolka on 10/14/13. // Created by Andrzej Kapolka on 10/14/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Inputs.slh@> <@include gpu/Inputs.slh@>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardTransform()$> <$declareStandardTransform()$>
const int MAX_TEXCOORDS = 2; const int MAX_TEXCOORDS = 2;
uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
out vec4 _position; out vec4 _position;
out vec2 _texCoord0; out vec2 _texCoord0;
out vec3 _normal; out vec3 _normal;
out vec3 _tangent; out vec3 _tangent;
out vec3 _color; out vec3 _color;
void main(void) { void main(void) {
// pass along the diffuse color // pass along the diffuse color
_color = inColor.rgb; _color = inColor.rgb;
// and the texture coordinates // and the texture coordinates
_texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.xy, 0.0, 1.0)).st; _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.xy, 0.0, 1.0)).st;
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$> <$transformModelToEyeAndClipPos(cam, obj, inPosition, _position, gl_Position)$>
<$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$> <$transformModelToEyeDir(cam, obj, inNormal.xyz, _normal)$>
<$transformModelToEyeDir(cam, obj, inTangent.xyz, _tangent)$> <$transformModelToEyeDir(cam, obj, inTangent.xyz, _tangent)$>
} }

View file

@ -1,26 +1,26 @@
<@include gpu/Config.slh@> <@include gpu/Config.slh@>
<$VERSION_HEADER$> <$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$> // Generated on <$_SCRIBE_DATE$>
// //
// model_shadow.vert // model_shadow.vert
// vertex shader // vertex shader
// //
// Created by Andrzej Kapolka on 3/24/14. // Created by Andrzej Kapolka on 3/24/14.
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Inputs.slh@> <@include gpu/Inputs.slh@>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardTransform()$> <$declareStandardTransform()$>
void main(void) { void main(void) {
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, inPosition, gl_Position)$> <$transformModelToClipPos(cam, obj, inPosition, gl_Position)$>
} }

View file

@ -1,48 +1,48 @@
<@include gpu/Config.slh@> <@include gpu/Config.slh@>
<$VERSION_HEADER$> <$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$> // Generated on <$_SCRIBE_DATE$>
// //
// skin_model.vert // skin_model.vert
// vertex shader // vertex shader
// //
// Created by Andrzej Kapolka on 10/14/13. // Created by Andrzej Kapolka on 10/14/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Inputs.slh@> <@include gpu/Inputs.slh@>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardTransform()$> <$declareStandardTransform()$>
<@include Skinning.slh@> <@include Skinning.slh@>
uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
out vec4 _position; out vec4 _position;
out vec2 _texCoord0; out vec2 _texCoord0;
out vec3 _normal; out vec3 _normal;
out vec3 _color; out vec3 _color;
void main(void) { void main(void) {
vec4 position = vec4(0.0, 0.0, 0.0, 0.0); vec4 position = vec4(0.0, 0.0, 0.0, 0.0);
vec3 interpolatedNormal = vec3(0.0, 0.0, 0.0); vec3 interpolatedNormal = vec3(0.0, 0.0, 0.0);
skinPositionNormal(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, position, interpolatedNormal); skinPositionNormal(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, position, interpolatedNormal);
// pass along the diffuse color // pass along the diffuse color
_color = inColor.rgb; _color = inColor.rgb;
// and the texture coordinates // and the texture coordinates
_texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st;
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$>
<$transformModelToEyeDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$> <$transformModelToEyeDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$>
_normal = interpolatedNormal.xyz; _normal = interpolatedNormal.xyz;
} }

View file

@ -1,56 +1,56 @@
<@include gpu/Config.slh@> <@include gpu/Config.slh@>
<$VERSION_HEADER$> <$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$> // Generated on <$_SCRIBE_DATE$>
// //
// skin_model_normal_map.vert // skin_model_normal_map.vert
// vertex shader // vertex shader
// //
// Created by Andrzej Kapolka on 10/29/13. // Created by Andrzej Kapolka on 10/29/13.
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Inputs.slh@> <@include gpu/Inputs.slh@>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardTransform()$> <$declareStandardTransform()$>
<@include Skinning.slh@> <@include Skinning.slh@>
uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
out vec4 _position; out vec4 _position;
out vec2 _texCoord0; out vec2 _texCoord0;
out vec3 _normal; out vec3 _normal;
out vec3 _tangent; out vec3 _tangent;
out vec3 _color; out vec3 _color;
void main(void) { void main(void) {
vec4 position = vec4(0.0, 0.0, 0.0, 0.0); vec4 position = vec4(0.0, 0.0, 0.0, 0.0);
vec4 interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0); vec4 interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0);
vec4 interpolatedTangent = vec4(0.0, 0.0, 0.0, 0.0); vec4 interpolatedTangent = vec4(0.0, 0.0, 0.0, 0.0);
skinPositionNormalTangent(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, inTangent.xyz, position, interpolatedNormal.xyz, interpolatedTangent.xyz); skinPositionNormalTangent(inSkinClusterIndex, inSkinClusterWeight, inPosition, inNormal.xyz, inTangent.xyz, position, interpolatedNormal.xyz, interpolatedTangent.xyz);
// pass along the diffuse color // pass along the diffuse color
_color = inColor.rgb; _color = inColor.rgb;
// and the texture coordinates // and the texture coordinates
_texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st; _texCoord0 = (texcoordMatrices[0] * vec4(inTexCoord0.st, 0.0, 1.0)).st;
interpolatedNormal = vec4(normalize(interpolatedNormal.xyz), 0.0); interpolatedNormal = vec4(normalize(interpolatedNormal.xyz), 0.0);
interpolatedTangent = vec4(normalize(interpolatedTangent.xyz), 0.0); interpolatedTangent = vec4(normalize(interpolatedTangent.xyz), 0.0);
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$>
<$transformModelToEyeDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$> <$transformModelToEyeDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$>
<$transformModelToEyeDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$> <$transformModelToEyeDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$>
_normal = interpolatedNormal.xyz; _normal = interpolatedNormal.xyz;
_tangent = interpolatedTangent.xyz; _tangent = interpolatedTangent.xyz;
} }

View file

@ -1,29 +1,29 @@
<@include gpu/Config.slh@> <@include gpu/Config.slh@>
<$VERSION_HEADER$> <$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$> // Generated on <$_SCRIBE_DATE$>
// //
// skin_model_shadow.vert // skin_model_shadow.vert
// vertex shader // vertex shader
// //
// Created by Andrzej Kapolka on 3/24/14. // Created by Andrzej Kapolka on 3/24/14.
// Copyright 2014 High Fidelity, Inc. // Copyright 2014 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Inputs.slh@> <@include gpu/Inputs.slh@>
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardTransform()$> <$declareStandardTransform()$>
<@include Skinning.slh@> <@include Skinning.slh@>
void main(void) { void main(void) {
vec4 position = vec4(0.0, 0.0, 0.0, 0.0); vec4 position = vec4(0.0, 0.0, 0.0, 0.0);
skinPosition(inSkinClusterIndex, inSkinClusterWeight, inPosition, position); skinPosition(inSkinClusterIndex, inSkinClusterWeight, inPosition, position);
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, position, gl_Position)$> <$transformModelToClipPos(cam, obj, position, gl_Position)$>
} }

View file

@ -1,163 +1,163 @@
// //
// DrawStatus.cpp // DrawStatus.cpp
// render/src/render // render/src/render
// //
// Created by Niraj Venkat on 6/29/15. // Created by Niraj Venkat on 6/29/15.
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "DrawStatus.h" #include "DrawStatus.h"
#include <algorithm> #include <algorithm>
#include <assert.h> #include <assert.h>
#include <PerfStat.h> #include <PerfStat.h>
#include <ViewFrustum.h> #include <ViewFrustum.h>
#include <RenderArgs.h> #include <RenderArgs.h>
#include <gpu/Context.h> #include <gpu/Context.h>
#include "drawItemBounds_vert.h" #include "drawItemBounds_vert.h"
#include "drawItemBounds_frag.h" #include "drawItemBounds_frag.h"
#include "drawItemStatus_vert.h" #include "drawItemStatus_vert.h"
#include "drawItemStatus_frag.h" #include "drawItemStatus_frag.h"
using namespace render; using namespace render;
const gpu::PipelinePointer& DrawStatus::getDrawItemBoundsPipeline() { const gpu::PipelinePointer& DrawStatus::getDrawItemBoundsPipeline() {
if (!_drawItemBoundsPipeline) { if (!_drawItemBoundsPipeline) {
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(drawItemBounds_vert))); auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(drawItemBounds_vert)));
auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawItemBounds_frag))); auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawItemBounds_frag)));
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps));
gpu::Shader::BindingSet slotBindings; gpu::Shader::BindingSet slotBindings;
gpu::Shader::makeProgram(*program, slotBindings); gpu::Shader::makeProgram(*program, slotBindings);
_drawItemBoundPosLoc = program->getUniforms().findLocation("inBoundPos"); _drawItemBoundPosLoc = program->getUniforms().findLocation("inBoundPos");
_drawItemBoundDimLoc = program->getUniforms().findLocation("inBoundDim"); _drawItemBoundDimLoc = program->getUniforms().findLocation("inBoundDim");
auto state = std::make_shared<gpu::State>(); auto state = std::make_shared<gpu::State>();
state->setDepthTest(true, false, gpu::LESS_EQUAL); state->setDepthTest(true, false, gpu::LESS_EQUAL);
// Blend on transparent // Blend on transparent
state->setBlendFunction(true, state->setBlendFunction(true,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO); gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO);
// Good to go add the brand new pipeline // Good to go add the brand new pipeline
_drawItemBoundsPipeline.reset(gpu::Pipeline::create(program, state)); _drawItemBoundsPipeline.reset(gpu::Pipeline::create(program, state));
} }
return _drawItemBoundsPipeline; return _drawItemBoundsPipeline;
} }
const gpu::PipelinePointer& DrawStatus::getDrawItemStatusPipeline() { const gpu::PipelinePointer& DrawStatus::getDrawItemStatusPipeline() {
if (!_drawItemStatusPipeline) { if (!_drawItemStatusPipeline) {
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(drawItemStatus_vert))); auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(drawItemStatus_vert)));
auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawItemStatus_frag))); auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(drawItemStatus_frag)));
gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps)); gpu::ShaderPointer program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps));
gpu::Shader::BindingSet slotBindings; gpu::Shader::BindingSet slotBindings;
gpu::Shader::makeProgram(*program, slotBindings); gpu::Shader::makeProgram(*program, slotBindings);
_drawItemStatusPosLoc = program->getUniforms().findLocation("inBoundPos"); _drawItemStatusPosLoc = program->getUniforms().findLocation("inBoundPos");
_drawItemStatusDimLoc = program->getUniforms().findLocation("inBoundDim"); _drawItemStatusDimLoc = program->getUniforms().findLocation("inBoundDim");
_drawItemStatusValueLoc = program->getUniforms().findLocation("inStatus"); _drawItemStatusValueLoc = program->getUniforms().findLocation("inStatus");
auto state = std::make_shared<gpu::State>(); auto state = std::make_shared<gpu::State>();
state->setDepthTest(false, false, gpu::LESS_EQUAL); state->setDepthTest(false, false, gpu::LESS_EQUAL);
// Blend on transparent // Blend on transparent
state->setBlendFunction(true, state->setBlendFunction(true,
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO); gpu::State::DEST_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ZERO);
// Good to go add the brand new pipeline // Good to go add the brand new pipeline
_drawItemStatusPipeline.reset(gpu::Pipeline::create(program, state)); _drawItemStatusPipeline.reset(gpu::Pipeline::create(program, state));
} }
return _drawItemStatusPipeline; return _drawItemStatusPipeline;
} }
void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) { void DrawStatus::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems) {
assert(renderContext->args); assert(renderContext->args);
assert(renderContext->args->_viewFrustum); assert(renderContext->args->_viewFrustum);
RenderArgs* args = renderContext->args; RenderArgs* args = renderContext->args;
auto& scene = sceneContext->_scene; auto& scene = sceneContext->_scene;
// FIrst thing, we collect the bound and the status for all the items we want to render // FIrst thing, we collect the bound and the status for all the items we want to render
int nbItems = 0; int nbItems = 0;
{ {
if (!_itemBounds) { if (!_itemBounds) {
_itemBounds = std::make_shared<gpu::Buffer>(); _itemBounds = std::make_shared<gpu::Buffer>();
} }
if (!_itemStatus) { if (!_itemStatus) {
_itemStatus = std::make_shared<gpu::Buffer>();; _itemStatus = std::make_shared<gpu::Buffer>();;
} }
_itemBounds->resize((inItems.size() * sizeof(AABox))); _itemBounds->resize((inItems.size() * sizeof(AABox)));
_itemStatus->resize((inItems.size() * sizeof(glm::vec4))); _itemStatus->resize((inItems.size() * sizeof(glm::vec4)));
AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData()); AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData()); glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
for (auto& item : inItems) { for (auto& item : inItems) {
if (!item.bounds.isInvalid()) { if (!item.bounds.isInvalid()) {
if (!item.bounds.isNull()) { if (!item.bounds.isNull()) {
(*itemAABox) = item.bounds; (*itemAABox) = item.bounds;
} else { } else {
(*itemAABox).setBox(item.bounds.getCorner(), 0.1f); (*itemAABox).setBox(item.bounds.getCorner(), 0.1f);
} }
auto& itemScene = scene->getItem(item.id); auto& itemScene = scene->getItem(item.id);
(*itemStatus) = itemScene.getStatusPackedValues(); (*itemStatus) = itemScene.getStatusPackedValues();
nbItems++; nbItems++;
itemAABox++; itemAABox++;
itemStatus++; itemStatus++;
} }
} }
} }
if (nbItems == 0) { if (nbItems == 0) {
return; return;
} }
// Allright, something to render let's do it // Allright, something to render let's do it
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
glm::mat4 projMat; glm::mat4 projMat;
Transform viewMat; Transform viewMat;
args->_viewFrustum->evalProjectionMatrix(projMat); args->_viewFrustum->evalProjectionMatrix(projMat);
args->_viewFrustum->evalViewTransform(viewMat); args->_viewFrustum->evalViewTransform(viewMat);
batch.setProjectionTransform(projMat); batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat); batch.setViewTransform(viewMat);
batch.setModelTransform(Transform()); batch.setModelTransform(Transform());
// bind the one gpu::Pipeline we need // bind the one gpu::Pipeline we need
batch.setPipeline(getDrawItemBoundsPipeline()); batch.setPipeline(getDrawItemBoundsPipeline());
AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData()); AABox* itemAABox = reinterpret_cast<AABox*> (_itemBounds->editData());
glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData()); glm::ivec4* itemStatus = reinterpret_cast<glm::ivec4*> (_itemStatus->editData());
const unsigned int VEC3_ADRESS_OFFSET = 3; const unsigned int VEC3_ADRESS_OFFSET = 3;
for (int i = 0; i < nbItems; i++) { for (int i = 0; i < nbItems; i++) {
batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*) (itemAABox + i)); batch._glUniform3fv(_drawItemBoundPosLoc, 1, (const float*) (itemAABox + i));
batch._glUniform3fv(_drawItemBoundDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET); batch._glUniform3fv(_drawItemBoundDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET);
batch.draw(gpu::LINES, 24, 0); batch.draw(gpu::LINES, 24, 0);
} }
batch.setPipeline(getDrawItemStatusPipeline()); batch.setPipeline(getDrawItemStatusPipeline());
for (int i = 0; i < nbItems; i++) { for (int i = 0; i < nbItems; i++) {
batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*) (itemAABox + i)); batch._glUniform3fv(_drawItemStatusPosLoc, 1, (const float*) (itemAABox + i));
batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET); batch._glUniform3fv(_drawItemStatusDimLoc, 1, ((const float*) (itemAABox + i)) + VEC3_ADRESS_OFFSET);
batch._glUniform4iv(_drawItemStatusValueLoc, 1, (const int*) (itemStatus + i)); batch._glUniform4iv(_drawItemStatusValueLoc, 1, (const int*) (itemStatus + i));
batch.draw(gpu::TRIANGLES, 24, 0); batch.draw(gpu::TRIANGLES, 24, 0);
} }
}); });
} }

View file

@ -1,43 +1,43 @@
// //
// DrawStatus.h // DrawStatus.h
// render/src/render // render/src/render
// //
// Created by Niraj Venkat on 6/29/15. // Created by Niraj Venkat on 6/29/15.
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#ifndef hifi_render_DrawStatus_h #ifndef hifi_render_DrawStatus_h
#define hifi_render_DrawStatus_h #define hifi_render_DrawStatus_h
#include "DrawTask.h" #include "DrawTask.h"
#include "gpu/Batch.h" #include "gpu/Batch.h"
namespace render { namespace render {
class DrawStatus { class DrawStatus {
int _drawItemBoundPosLoc = -1; int _drawItemBoundPosLoc = -1;
int _drawItemBoundDimLoc = -1; int _drawItemBoundDimLoc = -1;
int _drawItemStatusPosLoc = -1; int _drawItemStatusPosLoc = -1;
int _drawItemStatusDimLoc = -1; int _drawItemStatusDimLoc = -1;
int _drawItemStatusValueLoc = -1; int _drawItemStatusValueLoc = -1;
gpu::Stream::FormatPointer _drawItemFormat; gpu::Stream::FormatPointer _drawItemFormat;
gpu::PipelinePointer _drawItemBoundsPipeline; gpu::PipelinePointer _drawItemBoundsPipeline;
gpu::PipelinePointer _drawItemStatusPipeline; gpu::PipelinePointer _drawItemStatusPipeline;
gpu::BufferPointer _itemBounds; gpu::BufferPointer _itemBounds;
gpu::BufferPointer _itemStatus; gpu::BufferPointer _itemStatus;
public: public:
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems); void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems);
typedef Job::ModelI<DrawStatus, ItemIDsBounds> JobModel; typedef Job::ModelI<DrawStatus, ItemIDsBounds> JobModel;
const gpu::PipelinePointer& getDrawItemBoundsPipeline(); const gpu::PipelinePointer& getDrawItemBoundsPipeline();
const gpu::PipelinePointer& getDrawItemStatusPipeline(); const gpu::PipelinePointer& getDrawItemStatusPipeline();
}; };
} }
#endif // hifi_render_DrawStatus_h #endif // hifi_render_DrawStatus_h

View file

@ -19,39 +19,39 @@
uniform vec3 inBoundPos; uniform vec3 inBoundPos;
uniform vec3 inBoundDim; uniform vec3 inBoundDim;
void main(void) { void main(void) {
const vec4 UNIT_BOX[8] = vec4[8]( const vec4 UNIT_BOX[8] = vec4[8](
vec4(0.0, 0.0, 0.0, 1.0), vec4(0.0, 0.0, 0.0, 1.0),
vec4(1.0, 0.0, 0.0, 1.0), vec4(1.0, 0.0, 0.0, 1.0),
vec4(0.0, 1.0, 0.0, 1.0), vec4(0.0, 1.0, 0.0, 1.0),
vec4(1.0, 1.0, 0.0, 1.0), vec4(1.0, 1.0, 0.0, 1.0),
vec4(0.0, 0.0, 1.0, 1.0), vec4(0.0, 0.0, 1.0, 1.0),
vec4(1.0, 0.0, 1.0, 1.0), vec4(1.0, 0.0, 1.0, 1.0),
vec4(0.0, 1.0, 1.0, 1.0), vec4(0.0, 1.0, 1.0, 1.0),
vec4(1.0, 1.0, 1.0, 1.0) vec4(1.0, 1.0, 1.0, 1.0)
); );
const int UNIT_BOX_LINE_INDICES[24] = int[24]( const int UNIT_BOX_LINE_INDICES[24] = int[24](
0, 1, 0, 1,
1, 3, 1, 3,
3, 2, 3, 2,
2, 0, 2, 0,
4, 5, 4, 5,
5, 7, 5, 7,
7, 6, 7, 6,
6, 4, 6, 4,
2, 6, 2, 6,
3, 7, 3, 7,
0, 4, 0, 4,
1, 5 1, 5
); );
vec4 pos = UNIT_BOX[UNIT_BOX_LINE_INDICES[gl_VertexID]]; vec4 pos = UNIT_BOX[UNIT_BOX_LINE_INDICES[gl_VertexID]];
pos.xyz = inBoundPos + inBoundDim * pos.xyz; pos.xyz = inBoundPos + inBoundDim * pos.xyz;
// standard transform // standard transform
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, pos, gl_Position)$> <$transformModelToClipPos(cam, obj, pos, gl_Position)$>
// varTexcoord = (pos.xy + 1) * 0.5; // varTexcoord = (pos.xy + 1) * 0.5;
} }

View file

@ -1,103 +1,103 @@
<@include gpu/Config.slh@> <@include gpu/Config.slh@>
<$VERSION_HEADER$> <$VERSION_HEADER$>
// Generated on <$_SCRIBE_DATE$> // Generated on <$_SCRIBE_DATE$>
// //
// drawItemStatus.slv // drawItemStatus.slv
// vertex shader // vertex shader
// //
// Created by Sam Gateau on 6/30/2015. // Created by Sam Gateau on 6/30/2015.
// Copyright 2015 High Fidelity, Inc. // Copyright 2015 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
<@include gpu/Transform.slh@> <@include gpu/Transform.slh@>
<$declareStandardTransform()$> <$declareStandardTransform()$>
out vec4 varColor; out vec4 varColor;
uniform vec3 inBoundPos; uniform vec3 inBoundPos;
uniform vec3 inBoundDim; uniform vec3 inBoundDim;
uniform ivec4 inStatus; uniform ivec4 inStatus;
vec3 paintRainbow(float normalizedHue) { vec3 paintRainbow(float normalizedHue) {
float v = normalizedHue * 6.f; float v = normalizedHue * 6.f;
if (v < 0.f) { if (v < 0.f) {
return vec3(1.f, 0.f, 0.f); return vec3(1.f, 0.f, 0.f);
} else if (v < 1.f) { } else if (v < 1.f) {
return vec3(1.f, v, 0.f); return vec3(1.f, v, 0.f);
} else if (v < 2.f) { } else if (v < 2.f) {
return vec3(1.f - (v-1.f), 1.f, 0.f); return vec3(1.f - (v-1.f), 1.f, 0.f);
} else if (v < 3.f) { } else if (v < 3.f) {
return vec3(0.f, 1.f, (v-2.f)); return vec3(0.f, 1.f, (v-2.f));
} else if (v < 4.f) { } else if (v < 4.f) {
return vec3(0.f, 1.f - (v-3.f), 1.f ); return vec3(0.f, 1.f - (v-3.f), 1.f );
} else if (v < 5.f) { } else if (v < 5.f) {
return vec3((v-4.f), 0.f, 1.f ); return vec3((v-4.f), 0.f, 1.f );
} else if (v < 6.f) { } else if (v < 6.f) {
return vec3(1.f, 0.f, 1.f - (v-5.f)); return vec3(1.f, 0.f, 1.f - (v-5.f));
} else { } else {
return vec3(1.f, 0.f, 0.f); return vec3(1.f, 0.f, 0.f);
} }
} }
vec2 unpackStatus(int v) { vec2 unpackStatus(int v) {
return vec2(clamp(float(int((v >> 0) & 0xFFFF) - 32727) / 32727.0, -1.0, 1.0), return vec2(clamp(float(int((v >> 0) & 0xFFFF) - 32727) / 32727.0, -1.0, 1.0),
clamp(float(int((v >> 16) & 0xFFFF) - 32727) / 32727.0, -1.0, 1.0)); clamp(float(int((v >> 16) & 0xFFFF) - 32727) / 32727.0, -1.0, 1.0));
} }
void main(void) { void main(void) {
const vec2 ICON_PIXEL_SIZE = vec2(10, 10); const vec2 ICON_PIXEL_SIZE = vec2(10, 10);
const vec2 MARGIN_PIXEL_SIZE = vec2(2, 2); const vec2 MARGIN_PIXEL_SIZE = vec2(2, 2);
const int NUM_VERTICES = 6; const int NUM_VERTICES = 6;
const vec4 UNIT_QUAD[NUM_VERTICES] = vec4[NUM_VERTICES]( const vec4 UNIT_QUAD[NUM_VERTICES] = vec4[NUM_VERTICES](
vec4(-1.0, -1.0, 0.0, 1.0), vec4(-1.0, -1.0, 0.0, 1.0),
vec4(1.0, -1.0, 0.0, 1.0), vec4(1.0, -1.0, 0.0, 1.0),
vec4(-1.0, 1.0, 0.0, 1.0), vec4(-1.0, 1.0, 0.0, 1.0),
vec4(-1.0, 1.0, 0.0, 1.0), vec4(-1.0, 1.0, 0.0, 1.0),
vec4(1.0, -1.0, 0.0, 1.0), vec4(1.0, -1.0, 0.0, 1.0),
vec4(1.0, 1.0, 0.0, 1.0) vec4(1.0, 1.0, 0.0, 1.0)
); );
// anchor point in clip space // anchor point in clip space
vec4 anchorPoint = vec4(inBoundPos, 1.0) + vec4(inBoundDim, 0.0) * vec4(0.5, 0.5, 0.5, 0.0); vec4 anchorPoint = vec4(inBoundPos, 1.0) + vec4(inBoundDim, 0.0) * vec4(0.5, 0.5, 0.5, 0.0);
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToClipPos(cam, obj, anchorPoint, anchorPoint)$> <$transformModelToClipPos(cam, obj, anchorPoint, anchorPoint)$>
// Which icon are we dealing with ? // Which icon are we dealing with ?
int iconNum = gl_VertexID / NUM_VERTICES; int iconNum = gl_VertexID / NUM_VERTICES;
// if invalid, just kill // if invalid, just kill
if (inStatus[iconNum] == 0xFFFFFFFF) { if (inStatus[iconNum] == 0xFFFFFFFF) {
gl_Position = anchorPoint; gl_Position = anchorPoint;
varColor = vec4(1.0); varColor = vec4(1.0);
return; return;
} }
// unpack to get x and y satus // unpack to get x and y satus
vec2 iconStatus = unpackStatus(inStatus[iconNum]); vec2 iconStatus = unpackStatus(inStatus[iconNum]);
// Use the status for showing a color // Use the status for showing a color
varColor = vec4(paintRainbow(abs(iconStatus.y)), 1.0); varColor = vec4(paintRainbow(abs(iconStatus.y)), 1.0);
// Also changes the size of the notification // Also changes the size of the notification
vec2 iconScale = ICON_PIXEL_SIZE; vec2 iconScale = ICON_PIXEL_SIZE;
iconScale = max(vec2(1, 1), (iconScale * iconStatus.x)); iconScale = max(vec2(1, 1), (iconScale * iconStatus.x));
//Offset icon to the right based on the iconNum //Offset icon to the right based on the iconNum
vec2 offset = vec2(iconNum * (ICON_PIXEL_SIZE.x + MARGIN_PIXEL_SIZE.x), 0); vec2 offset = vec2(iconNum * (ICON_PIXEL_SIZE.x + MARGIN_PIXEL_SIZE.x), 0);
// Final position in pixel space // Final position in pixel space
int twoTriID = gl_VertexID - iconNum * NUM_VERTICES; int twoTriID = gl_VertexID - iconNum * NUM_VERTICES;
vec4 pos = UNIT_QUAD[twoTriID]; vec4 pos = UNIT_QUAD[twoTriID];
vec2 quadPixelPos = offset.xy + pos.xy * 0.5 * iconScale; vec2 quadPixelPos = offset.xy + pos.xy * 0.5 * iconScale;
vec4 viewport; vec4 viewport;
<$transformCameraViewport(cam, viewport)$>; <$transformCameraViewport(cam, viewport)$>;
vec2 pixelToClip = vec2(2.0 / viewport.z, 2.0 / viewport.w); vec2 pixelToClip = vec2(2.0 / viewport.z, 2.0 / viewport.w);
gl_Position = anchorPoint + (anchorPoint.w * vec4(quadPixelPos * pixelToClip, 0.0, 0.0)); gl_Position = anchorPoint + (anchorPoint.w * vec4(quadPixelPos * pixelToClip, 0.0, 0.0));
} }

View file

@ -90,8 +90,8 @@ void SceneScriptingInterface::setStageSunModelEnable(bool isEnabled) {
_skyStage->setSunModelEnable(isEnabled); _skyStage->setSunModelEnable(isEnabled);
} }
bool SceneScriptingInterface::isStageSunModelEnabled() const { bool SceneScriptingInterface::isStageSunModelEnabled() const {
return _skyStage->isSunModelEnabled(); return _skyStage->isSunModelEnabled();
} }
void SceneScriptingInterface::setBackgroundMode(const QString& mode) { void SceneScriptingInterface::setBackgroundMode(const QString& mode) {

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
// //
// TextTemplate.cpp // TextTemplate.cpp
// tools/shaderScribe/src // tools/shaderScribe/src
@ -7,198 +7,198 @@
// Copyright 2013 High Fidelity, Inc. // Copyright 2013 High Fidelity, Inc.
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
#ifndef hifi_TEXT_TEMPLATE_H #ifndef hifi_TEXT_TEMPLATE_H
#define hifi_TEXT_TEMPLATE_H #define hifi_TEXT_TEMPLATE_H
#include <list> #include <list>
#include <vector> #include <vector>
#include <map> #include <map>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <memory> #include <memory>
class TextTemplate { class TextTemplate {
public: public:
typedef std::shared_ptr< TextTemplate > Pointer; typedef std::shared_ptr< TextTemplate > Pointer;
typedef std::string String; typedef std::string String;
typedef std::vector< String > StringVector; typedef std::vector< String > StringVector;
typedef std::map< String, String > Vars; typedef std::map< String, String > Vars;
typedef std::map< String, TextTemplate::Pointer > Includes; typedef std::map< String, TextTemplate::Pointer > Includes;
class Tag { class Tag {
public: public:
enum Type { enum Type {
VARIABLE = 0, VARIABLE = 0,
COMMAND, COMMAND,
REMARK, REMARK,
INVALID = -1, INVALID = -1,
}; };
static const char BEGIN = '<'; static const char BEGIN = '<';
static const char END = '>'; static const char END = '>';
static const char VAR = '$'; static const char VAR = '$';
static const char COM = '@'; static const char COM = '@';
static const char REM = '!'; static const char REM = '!';
}; };
class Command { class Command {
public: public:
typedef std::vector< Command > vector; typedef std::vector< Command > vector;
enum Type { enum Type {
VAR = 0, VAR = 0,
BLOCK, BLOCK,
FUNC, FUNC,
ENDFUNC, ENDFUNC,
IFBLOCK, IFBLOCK,
IF, IF,
ELIF, ELIF,
ELSE, ELSE,
ENDIF, ENDIF,
FOR, FOR,
ENDFOR, ENDFOR,
INCLUDE, INCLUDE,
DEF, DEF,
}; };
Type type; Type type;
std::vector< String > arguments; std::vector< String > arguments;
bool isBlockEnd() { bool isBlockEnd() {
switch (type) { switch (type) {
case ENDFUNC: case ENDFUNC:
case ENDIF: case ENDIF:
case ENDFOR: case ENDFOR:
case INCLUDE: case INCLUDE:
case DEF: case DEF:
case VAR: case VAR:
return true; return true;
default: default:
return false; return false;
} }
} }
}; };
class Block { class Block {
public: public:
typedef std::shared_ptr<Block> Pointer; typedef std::shared_ptr<Block> Pointer;
typedef std::vector< Block::Pointer > Vector; typedef std::vector< Block::Pointer > Vector;
Block::Pointer parent; Block::Pointer parent;
Command command; Command command;
Vector blocks; Vector blocks;
std::stringstream ostr; std::stringstream ostr;
String sourceName; String sourceName;
Block(const String& sourceFilename) : Block(const String& sourceFilename) :
sourceName(sourceFilename) {} sourceName(sourceFilename) {}
static void addNewBlock(const Block::Pointer& parent, const Block::Pointer& block); static void addNewBlock(const Block::Pointer& parent, const Block::Pointer& block);
static const Block::Pointer& getCurrentBlock(const Block::Pointer& block); static const Block::Pointer& getCurrentBlock(const Block::Pointer& block);
static void displayTree(const Block::Pointer& block, std::ostream& dst, int& level); static void displayTree(const Block::Pointer& block, std::ostream& dst, int& level);
}; };
class Funcs { class Funcs {
public: public:
typedef std::map< String, Block::Pointer > map; typedef std::map< String, Block::Pointer > map;
Funcs(); Funcs();
~Funcs(); ~Funcs();
const Block::Pointer findFunc(const char* func); const Block::Pointer findFunc(const char* func);
const Block::Pointer addFunc(const char* func, const Block::Pointer& root); const Block::Pointer addFunc(const char* func, const Block::Pointer& root);
map _funcs; map _funcs;
protected: protected:
}; };
class Config { class Config {
public: public:
typedef std::shared_ptr< Config > Pointer; typedef std::shared_ptr< Config > Pointer;
typedef bool (*IncluderCallback) (const Config::Pointer& config, const char* filename, String& source); typedef bool (*IncluderCallback) (const Config::Pointer& config, const char* filename, String& source);
Includes _includes; Includes _includes;
Funcs _funcs; Funcs _funcs;
std::ostream* _logStream; std::ostream* _logStream;
int _numErrors; int _numErrors;
IncluderCallback _includerCallback; IncluderCallback _includerCallback;
StringVector _paths; StringVector _paths;
Config(); Config();
static const TextTemplate::Pointer addInclude(const Config::Pointer& config, const char* include); static const TextTemplate::Pointer addInclude(const Config::Pointer& config, const char* include);
const TextTemplate::Pointer findInclude(const char* include); const TextTemplate::Pointer findInclude(const char* include);
void addIncludePath(const char* path); void addIncludePath(const char* path);
void displayTree(std::ostream& dst, int& level) const; void displayTree(std::ostream& dst, int& level) const;
}; };
static bool loadFile(const Config::Pointer& config, const char* filename, String& source); static bool loadFile(const Config::Pointer& config, const char* filename, String& source);
TextTemplate(const String& name, const Config::Pointer& config = std::make_shared<Config>()); TextTemplate(const String& name, const Config::Pointer& config = std::make_shared<Config>());
~TextTemplate(); ~TextTemplate();
// Scibe does all the job of parsing an inout template stream and then gneerating theresulting stream using the vars // Scibe does all the job of parsing an inout template stream and then gneerating theresulting stream using the vars
int scribe(std::ostream& dst, std::istream& src, Vars& vars); int scribe(std::ostream& dst, std::istream& src, Vars& vars);
int parse(std::istream& src); int parse(std::istream& src);
int generate(std::ostream& dst, Vars& vars); int generate(std::ostream& dst, Vars& vars);
const Config::Pointer config() { return _config; } const Config::Pointer config() { return _config; }
void displayTree(std::ostream& dst, int& level) const; void displayTree(std::ostream& dst, int& level) const;
protected: protected:
Config::Pointer _config; Config::Pointer _config;
Block::Pointer _root; Block::Pointer _root;
int _numErrors; int _numErrors;
bool _steppingStarted; bool _steppingStarted;
bool grabUntilBeginTag(std::istream* str, String& grabbed, Tag::Type& tagType); bool grabUntilBeginTag(std::istream* str, String& grabbed, Tag::Type& tagType);
bool grabUntilEndTag(std::istream* str, String& grabbed, Tag::Type& tagType); bool grabUntilEndTag(std::istream* str, String& grabbed, Tag::Type& tagType);
bool stepForward(std::istream* str, String& grabbed, String& tag, Tag::Type& tagType, Tag::Type& nextTagType); bool stepForward(std::istream* str, String& grabbed, String& tag, Tag::Type& tagType, Tag::Type& nextTagType);
bool grabFirstToken(String& src, String& token, String& reminder); bool grabFirstToken(String& src, String& token, String& reminder);
bool convertExpressionToArguments(String& src, std::vector< String >& arguments); bool convertExpressionToArguments(String& src, std::vector< String >& arguments);
bool convertExpressionToDefArguments(String& src, std::vector< String >& arguments); bool convertExpressionToDefArguments(String& src, std::vector< String >& arguments);
bool convertExpressionToFuncArguments(String& src, std::vector< String >& arguments); bool convertExpressionToFuncArguments(String& src, std::vector< String >& arguments);
// Filter between var, command or comments // Filter between var, command or comments
const Block::Pointer processStep(const Block::Pointer& block, String& grabbed, String& tag, Tag::Type& tagType); const Block::Pointer processStep(const Block::Pointer& block, String& grabbed, String& tag, Tag::Type& tagType);
const Block::Pointer processStepVar(const Block::Pointer& block, String& grabbed, String& tag); const Block::Pointer processStepVar(const Block::Pointer& block, String& grabbed, String& tag);
const Block::Pointer processStepCommand(const Block::Pointer& block, String& grabbed, String& tag); const Block::Pointer processStepCommand(const Block::Pointer& block, String& grabbed, String& tag);
const Block::Pointer processStepRemark(const Block::Pointer& block, String& grabbed, String& tag); const Block::Pointer processStepRemark(const Block::Pointer& block, String& grabbed, String& tag);
// Define command // Define command
const Block::Pointer processStepDef(const Block::Pointer& block, String& grabbed, String& tag); const Block::Pointer processStepDef(const Block::Pointer& block, String& grabbed, String& tag);
// If commands // If commands
const Block::Pointer processStepCommandIf(const Block::Pointer& block, String& grabbed, String& expression); const Block::Pointer processStepCommandIf(const Block::Pointer& block, String& grabbed, String& expression);
const Block::Pointer processStepCommandEndIf(const Block::Pointer& block, String& grabbed, String& expression); const Block::Pointer processStepCommandEndIf(const Block::Pointer& block, String& grabbed, String& expression);
const Block::Pointer processStepCommandElif(const Block::Pointer& block, String& grabbed, String& expression); const Block::Pointer processStepCommandElif(const Block::Pointer& block, String& grabbed, String& expression);
const Block::Pointer processStepCommandElse(const Block::Pointer& block, String& grabbed, String& expression); const Block::Pointer processStepCommandElse(const Block::Pointer& block, String& grabbed, String& expression);
// Include command // Include command
const Block::Pointer processStepInclude(const Block::Pointer& block, String& grabbed, String& tag); const Block::Pointer processStepInclude(const Block::Pointer& block, String& grabbed, String& tag);
// Function command // Function command
const Block::Pointer processStepFunc(const Block::Pointer& block, String& grabbed, String& tag); const Block::Pointer processStepFunc(const Block::Pointer& block, String& grabbed, String& tag);
const Block::Pointer processStepEndFunc(const Block::Pointer& block, String& grabbed, String& tag); const Block::Pointer processStepEndFunc(const Block::Pointer& block, String& grabbed, String& tag);
// Generation // Generation
int generateTree(std::ostream& dst, const Block::Pointer& block, Vars& vars); int generateTree(std::ostream& dst, const Block::Pointer& block, Vars& vars);
int evalBlockGeneration(std::ostream& dst, const Block::Pointer& block, Vars& vars, Block::Pointer& branch); int evalBlockGeneration(std::ostream& dst, const Block::Pointer& block, Vars& vars, Block::Pointer& branch);
// Errors // Errors
std::ostream& log() { return (* _config->_logStream); } std::ostream& log() { return (* _config->_logStream); }
void logError(const Block::Pointer& block, const char* error, ...); void logError(const Block::Pointer& block, const char* error, ...);
}; };
#endif #endif