Fix MultiMeshViewer for dev branch

This commit is contained in:
Sheng Fu 2013-08-12 11:00:34 -07:00
parent e9e6183a87
commit 318922d7cf
6 changed files with 389 additions and 382 deletions

View File

@ -1,58 +1,26 @@
#
# Copyright (C) Pixar. All rights reserved.
# Copyright 2013 Pixar
#
# This license governs use of the accompanying software. If you
# use the software, you accept this license. If you do not accept
# the license, do not use the software.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License
# and the following modification to it: Section 6 Trademarks.
# deleted and replaced with:
#
# 1. Definitions
# The terms "reproduce," "reproduction," "derivative works," and
# "distribution" have the same meaning here as under U.S.
# copyright law. A "contribution" is the original software, or
# any additions or changes to the software.
# A "contributor" is any person or entity that distributes its
# contribution under this license.
# "Licensed patents" are a contributor's patent claims that read
# directly on its contribution.
# 6. Trademarks. This License does not grant permission to use the
# trade names, trademarks, service marks, or product names of the
# Licensor and its affiliates, except as required for reproducing
# the content of the NOTICE file.
#
# 2. Grant of Rights
# (A) Copyright Grant- Subject to the terms of this license,
# including the license conditions and limitations in section 3,
# each contributor grants you a non-exclusive, worldwide,
# royalty-free copyright license to reproduce its contribution,
# prepare derivative works of its contribution, and distribute
# its contribution or any derivative works that you create.
# (B) Patent Grant- Subject to the terms of this license,
# including the license conditions and limitations in section 3,
# each contributor grants you a non-exclusive, worldwide,
# royalty-free license under its licensed patents to make, have
# made, use, sell, offer for sale, import, and/or otherwise
# dispose of its contribution in the software or derivative works
# of the contribution in the software.
# You may obtain a copy of the License at
#
# 3. Conditions and Limitations
# (A) No Trademark License- This license does not grant you
# rights to use any contributor's name, logo, or trademarks.
# (B) If you bring a patent claim against any contributor over
# patents that you claim are infringed by the software, your
# patent license from such contributor to the software ends
# automatically.
# (C) If you distribute any portion of the software, you must
# retain all copyright, patent, trademark, and attribution
# notices that are present in the software.
# (D) If you distribute any portion of the software in source
# code form, you may do so only under this license by including a
# complete copy of this license with your distribution. If you
# distribute any portion of the software in compiled or object
# code form, you may only do so under a license that complies
# with this license.
# (E) The software is licensed "as-is." You bear the risk of
# using it. The contributors give no express warranties,
# guarantees or conditions. You may have additional consumer
# rights under your local laws which this license cannot change.
# To the extent permitted under your local laws, the contributors
# exclude the implied warranties of merchantability, fitness for
# a particular purpose and non-infringement.
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the
# License.
#
# *** glViewer ***
@ -65,17 +33,26 @@ set(SHADER_FILES
set(PLATFORM_LIBRARIES
${OSD_LINK_TARGET}
${OPENGL_LIBRARY}
${GLEW_LIBRARY}
${GLFW_LIBRARIES}
)
include_directories(
${PROJECT_SOURCE_DIR}/opensubdiv
${PROJECT_SOURCE_DIR}/regression
${GLEW_INCLUDE_DIR}
${GLFW_INCLUDE_DIR}
)
if ( GLEW_FOUND )
include_directories(${GLEW_INCLUDE_DIR})
list(APPEND PLATFORM_LIBRARIES ${GLEW_LIBRARY})
endif()
if( TBB_FOUND )
list(APPEND PLATFORM_LIBRARIES
${TBB_LIBRARIES}
)
endif()
#-------------------------------------------------------------------------------
# Shader Stringification
# We want to use preprocessor include directives to include GLSL and OpenCL
@ -103,6 +80,7 @@ _add_glfw_executable(glMultiMeshViewer
../common/font_image.cpp
../common/hud.cpp
../common/gl_hud.cpp
../common/patchColors.cpp
${SHADER_FILES}
${INC_FILES}
)

View File

@ -1,59 +1,57 @@
//
// Copyright (C) Pixar. All rights reserved.
// Copyright 2013 Pixar
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License
// and the following modification to it: Section 6 Trademarks.
// deleted and replaced with:
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
// 6. Trademarks. This License does not grant permission to use the
// trade names, trademarks, service marks, or product names of the
// Licensor and its affiliates, except as required for reproducing
// the content of the NOTICE file.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
// You may obtain a copy of the License at
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the
// License.
//
#if defined(VARYING_COLOR) || defined(FACEVARYING_COLOR)
#undef OSD_USER_VARYING_DECLARE
#define OSD_USER_VARYING_DECLARE \
vec3 color;
#undef OSD_USER_VARYING_ATTRIBUTE_DECLARE
#define OSD_USER_VARYING_ATTRIBUTE_DECLARE \
layout(location = 1) in vec3 color;
#undef OSD_USER_VARYING_PER_VERTEX
#define OSD_USER_VARYING_PER_VERTEX() \
outpt.color = color
#undef OSD_USER_VARYING_PER_CONTROL_POINT
#define OSD_USER_VARYING_PER_CONTROL_POINT(ID_OUT, ID_IN) \
outpt[ID_OUT].color = inpt[ID_IN].color
#undef OSD_USER_VARYING_PER_EVAL_POINT
#define OSD_USER_VARYING_PER_EVAL_POINT(UV, a, b, c, d) \
outpt.color = \
mix(mix(inpt[a].color, inpt[b].color, UV.x), \
mix(inpt[c].color, inpt[d].color, UV.x), UV.y)
#else
#define OSD_USER_VARYING_DECLARE
#define OSD_USER_VARYING_ATTRIBUTE_DECLARE
#define OSD_USER_VARYING_PER_VERTEX()
#define OSD_USER_VARYING_PER_CONTROL_POINT(ID_OUT, ID_IN)
#define OSD_USER_VARYING_PER_EVAL_POINT(UV, a, b, c, d)
#endif
//--------------------------------------------------------------
// Vertex Shader
@ -61,16 +59,17 @@
#ifdef VERTEX_SHADER
layout (location=0) in vec4 position;
layout (location=1) in vec3 normal;
OSD_USER_VARYING_ATTRIBUTE_DECLARE
out block {
OutputVertex v;
} output;
OSD_USER_VARYING_DECLARE
} outpt;
void main()
{
output.v.position = ModelViewMatrix * position;
output.v.normal = (ModelViewMatrix * vec4(normal, 0.0)).xyz;
outpt.v.position = ModelViewMatrix * position;
OSD_USER_VARYING_PER_VERTEX();
}
#endif
@ -84,54 +83,57 @@ void main()
layout(lines_adjacency) in;
layout(triangle_strip, max_vertices = 4) out;
#define EDGE_VERTS 4
in block {
OutputVertex v;
} input[4];
#endif // PRIM_QUAD
#ifdef PRIM_TRI
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
#define EDGE_VERTS 3
in block {
OutputVertex v;
} input[3];
#endif // PRIM_TRI
#ifdef PRIM_POINT
layout(points) in;
layout(points, max_vertices = 1) out;
in block {
OutputVertex v;
} input[1];
#endif // PRIM_POINT
layout(triangle_strip, max_vertices = EDGE_VERTS) out;
in block {
OutputVertex v;
OSD_USER_VARYING_DECLARE
} inpt[EDGE_VERTS];
out block {
OutputVertex v;
} output;
noperspective out vec4 edgeDistance;
OSD_USER_VARYING_DECLARE
} outpt;
void emit(int index, vec3 normal)
{
output.v.position = input[index].v.position;
outpt.v.position = inpt[index].v.position;
#ifdef SMOOTH_NORMALS
output.v.normal = input[index].v.normal;
outpt.v.normal = inpt[index].v.normal;
#else
output.v.normal = normal;
outpt.v.normal = normal;
#endif
gl_Position = ProjectionMatrix * input[index].v.position;
#ifdef VARYING_COLOR
outpt.color = inpt[index].color;
#endif
#ifdef FACEVARYING_COLOR
#ifdef UNIFORM_SUBDIVISION
vec2 quadst[4] = vec2[](vec2(0,0), vec2(1,0), vec2(1,1), vec2(0,1));
vec2 st = quadst[index];
#else
vec2 st = inpt[index].v.tessCoord;
#endif
vec2 uv;
OSD_COMPUTE_FACE_VARYING_2(uv, /*fvarOffset=*/0, st);
outpt.color = vec3(uv.s, uv.t, 0);
#endif
gl_Position = ProjectionMatrix * inpt[index].v.position;
EmitVertex();
}
@ -147,18 +149,18 @@ float edgeDistance(vec4 p, vec4 p0, vec4 p1)
void emit(int index, vec3 normal, vec4 edgeVerts[EDGE_VERTS])
{
output.v.edgeDistance[0] =
outpt.edgeDistance[0] =
edgeDistance(edgeVerts[index], edgeVerts[0], edgeVerts[1]);
output.v.edgeDistance[1] =
outpt.edgeDistance[1] =
edgeDistance(edgeVerts[index], edgeVerts[1], edgeVerts[2]);
#ifdef PRIM_TRI
output.v.edgeDistance[2] =
outpt.edgeDistance[2] =
edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[0]);
#endif
#ifdef PRIM_QUAD
output.v.edgeDistance[2] =
outpt.edgeDistance[2] =
edgeDistance(edgeVerts[index], edgeVerts[2], edgeVerts[3]);
output.v.edgeDistance[3] =
outpt.edgeDistance[3] =
edgeDistance(edgeVerts[index], edgeVerts[3], edgeVerts[0]);
#endif
@ -170,22 +172,18 @@ void main()
{
gl_PrimitiveID = gl_PrimitiveIDIn;
#ifdef PRIM_POINT
emit(0, vec3(0));
#endif
#ifdef PRIM_QUAD
vec3 A = (input[0].v.position - input[1].v.position).xyz;
vec3 B = (input[3].v.position - input[1].v.position).xyz;
vec3 C = (input[2].v.position - input[1].v.position).xyz;
vec3 A = (inpt[0].v.position - inpt[1].v.position).xyz;
vec3 B = (inpt[3].v.position - inpt[1].v.position).xyz;
vec3 C = (inpt[2].v.position - inpt[1].v.position).xyz;
vec3 n0 = normalize(cross(B, A));
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
vec4 edgeVerts[EDGE_VERTS];
edgeVerts[0] = ProjectionMatrix * input[0].v.position;
edgeVerts[1] = ProjectionMatrix * input[1].v.position;
edgeVerts[2] = ProjectionMatrix * input[2].v.position;
edgeVerts[3] = ProjectionMatrix * input[3].v.position;
edgeVerts[0] = ProjectionMatrix * inpt[0].v.position;
edgeVerts[1] = ProjectionMatrix * inpt[1].v.position;
edgeVerts[2] = ProjectionMatrix * inpt[2].v.position;
edgeVerts[3] = ProjectionMatrix * inpt[3].v.position;
edgeVerts[0].xy /= edgeVerts[0].w;
edgeVerts[1].xy /= edgeVerts[1].w;
@ -205,15 +203,15 @@ void main()
#endif // PRIM_QUAD
#ifdef PRIM_TRI
vec3 A = (input[1].v.position - input[0].v.position).xyz;
vec3 B = (input[2].v.position - input[0].v.position).xyz;
vec3 A = (inpt[1].v.position - inpt[0].v.position).xyz;
vec3 B = (inpt[2].v.position - inpt[0].v.position).xyz;
vec3 n0 = normalize(cross(B, A));
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
vec4 edgeVerts[EDGE_VERTS];
edgeVerts[0] = ProjectionMatrix * input[0].v.position;
edgeVerts[1] = ProjectionMatrix * input[1].v.position;
edgeVerts[2] = ProjectionMatrix * input[2].v.position;
edgeVerts[0] = ProjectionMatrix * inpt[0].v.position;
edgeVerts[1] = ProjectionMatrix * inpt[1].v.position;
edgeVerts[2] = ProjectionMatrix * inpt[2].v.position;
edgeVerts[0].xy /= edgeVerts[0].w;
edgeVerts[1].xy /= edgeVerts[1].w;
@ -241,7 +239,9 @@ void main()
in block {
OutputVertex v;
} input;
noperspective in vec4 edgeDistance;
OSD_USER_VARYING_DECLARE
} inpt;
out vec4 outColor;
@ -262,7 +262,7 @@ uniform vec4 diffuseColor = vec4(1);
uniform vec4 ambientColor = vec4(1);
vec4
lighting(vec3 Peye, vec3 Neye)
lighting(vec4 diffuse, vec3 Peye, vec3 Neye)
{
vec4 color = vec4(0);
@ -280,7 +280,7 @@ lighting(vec3 Peye, vec3 Neye)
float s = pow(max(0.0, dot(n, h)), 500.0f);
color += lightSource[i].ambient * ambientColor
+ d * lightSource[i].diffuse * diffuseColor
+ d * lightSource[i].diffuse * diffuse
+ s * lightSource[i].specular;
}
@ -288,27 +288,18 @@ lighting(vec3 Peye, vec3 Neye)
return color;
}
#ifdef PRIM_POINT
uniform vec4 fragColor;
void
main()
{
outColor = fragColor;
}
#endif
vec4
edgeColor(vec4 Cfill, vec4 edgeDistance)
{
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
#ifdef PRIM_TRI
float d =
min(input.v.edgeDistance[0], min(input.v.edgeDistance[1], input.v.edgeDistance[2]));
min(inpt.edgeDistance[0], min(inpt.edgeDistance[1], inpt.edgeDistance[2]));
#endif
#ifdef PRIM_QUAD
float d =
min(min(input.v.edgeDistance[0], input.v.edgeDistance[1]),
min(input.v.edgeDistance[2], input.v.edgeDistance[3]));
min(min(inpt.edgeDistance[0], inpt.edgeDistance[1]),
min(inpt.edgeDistance[2], inpt.edgeDistance[3]));
#endif
vec4 Cedge = vec4(1.0, 1.0, 0.0, 1.0);
float p = exp2(-2 * d * d);
@ -326,11 +317,22 @@ edgeColor(vec4 Cfill, vec4 edgeDistance)
void
main()
{
vec3 N = (gl_FrontFacing ? input.v.normal : -input.v.normal);
vec4 Cf = lighting(input.v.position.xyz, N);
vec3 N = (gl_FrontFacing ? inpt.v.normal : -inpt.v.normal);
#if defined(VARYING_COLOR)
vec4 color = vec4(inpt.color, 1);
#elif defined(FACEVARYING_COLOR)
// generating a checkerboard pattern
vec4 color = vec4(inpt.color.rg,
int(floor(20*inpt.color.r)+floor(20*inpt.color.g))&1, 1);
#else
vec4 color = diffuseColor;
#endif
vec4 Cf = lighting(color, inpt.v.position.xyz, N);
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
Cf = edgeColor(Cf, input.v.edgeDistance);
Cf = edgeColor(Cf, inpt.edgeDistance);
#endif
outColor = Cf;

View File

@ -1,58 +1,26 @@
//
// Copyright (C) Pixar. All rights reserved.
// Copyright 2013 Pixar
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License
// and the following modification to it: Section 6 Trademarks.
// deleted and replaced with:
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
// 6. Trademarks. This License does not grant permission to use the
// trade names, trademarks, service marks, or product names of the
// Licensor and its affiliates, except as required for reproducing
// the content of the NOTICE file.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
// You may obtain a copy of the License at
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the
// License.
//
layout(std140) uniform Transform {
@ -68,15 +36,19 @@ layout(std140) uniform Transform {
#ifdef VERTEX_SHADER
layout (location=0) in vec4 position;
layout (location=1) in vec3 normal;
out vec4 vPosition;
out vec3 vNormal;
#ifdef VARYING_COLOR
layout (location=1) in vec3 color;
out vec3 vColor;
#endif
void main()
{
vPosition = ModelViewMatrix * position;
vNormal = (ModelViewMatrix * vec4(normal, 0.0)).xyz;
#ifdef VARYING_COLOR
vColor = color;
#endif
}
#endif
@ -90,41 +62,32 @@ void main()
layout(lines_adjacency) in;
layout(triangle_strip, max_vertices = 4) out;
#define EDGE_VERTS 4
in vec4 vPosition[4];
in vec3 vNormal[4];
#endif // PRIM_QUAD
#ifdef PRIM_TRI
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
#define EDGE_VERTS 3
in vec4 vPosition[3];
in vec3 vNormal[3];
#endif // PRIM_TRI
#ifdef PRIM_POINT
layout(triangle_strip, max_vertices = EDGE_VERTS) out;
layout(points) in;
layout(points, max_vertices = 1) out;
in vec4 vPosition[EDGE_VERTS];
#ifdef VARYING_COLOR
in vec3 vColor[EDGE_VERTS];
#endif
in vec4 vPosition[1];
in vec3 vNormal[1];
#endif // PRIM_POINT
out vec4 gPosition;
out vec3 gNormal;
noperspective out vec4 gEdgeDistance;
#ifdef VARYING_COLOR
out vec3 gColor;
#endif
void emit(int index, vec3 normal)
{
@ -133,6 +96,9 @@ void emit(int index, vec3 normal)
gNormal = vNormal[index];
#else
gNormal = normal;
#endif
#ifdef VARYING_COLOR
gColor = vColor[index];
#endif
gl_Position = ProjectionMatrix * vPosition[index];
EmitVertex();
@ -245,6 +211,9 @@ void main()
in vec4 gPosition;
in vec3 gNormal;
noperspective in vec4 gEdgeDistance;
#ifdef VARYING_COLOR
in vec3 gColor;
#endif
out vec4 outColor;
@ -265,7 +234,7 @@ uniform vec4 diffuseColor = vec4(1);
uniform vec4 ambientColor = vec4(1);
vec4
lighting(vec3 Peye, vec3 Neye)
lighting(vec4 diffuse, vec3 Peye, vec3 Neye)
{
vec4 color = vec4(0);
@ -283,7 +252,7 @@ lighting(vec3 Peye, vec3 Neye)
float s = pow(max(0.0, dot(n, h)), 500.0f);
color += lightSource[i].ambient * ambientColor
+ d * lightSource[i].diffuse * diffuseColor
+ d * lightSource[i].diffuse * diffuse
+ s * lightSource[i].specular;
}
@ -330,7 +299,12 @@ void
main()
{
vec3 N = (gl_FrontFacing ? gNormal : -gNormal);
vec4 Cf = lighting(gPosition.xyz, N);
#ifdef VARYING_COLOR
vec4 color = vec4(gColor, 1);
#else
vec4 color = diffuseColor;
#endif
vec4 Cf = lighting(color, gPosition.xyz, N);
#if defined(GEOMETRY_OUT_WIRE) || defined(GEOMETRY_OUT_LINE)
Cf = edgeColor(Cf, gEdgeDistance);

View File

@ -1,62 +1,34 @@
//
// Copyright (C) Pixar. All rights reserved.
// Copyright 2013 Pixar
//
// This license governs use of the accompanying software. If you
// use the software, you accept this license. If you do not accept
// the license, do not use the software.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License
// and the following modification to it: Section 6 Trademarks.
// deleted and replaced with:
//
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and
// "distribution" have the same meaning here as under U.S.
// copyright law. A "contribution" is the original software, or
// any additions or changes to the software.
// A "contributor" is any person or entity that distributes its
// contribution under this license.
// "Licensed patents" are a contributor's patent claims that read
// directly on its contribution.
// 6. Trademarks. This License does not grant permission to use the
// trade names, trademarks, service marks, or product names of the
// Licensor and its affiliates, except as required for reproducing
// the content of the NOTICE file.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free copyright license to reproduce its contribution,
// prepare derivative works of its contribution, and distribute
// its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license,
// including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide,
// royalty-free license under its licensed patents to make, have
// made, use, sell, offer for sale, import, and/or otherwise
// dispose of its contribution in the software or derivative works
// of the contribution in the software.
// You may obtain a copy of the License at
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you
// rights to use any contributor's name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over
// patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends
// automatically.
// (C) If you distribute any portion of the software, you must
// retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source
// code form, you may do so only under this license by including a
// complete copy of this license with your distribution. If you
// distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies
// with this license.
// (E) The software is licensed "as-is." You bear the risk of
// using it. The contributors give no express warranties,
// guarantees or conditions. You may have additional consumer
// rights under your local laws which this license cannot change.
// To the extent permitted under your local laws, the contributors
// exclude the implied warranties of merchantability, fitness for
// a particular purpose and non-infringement.
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific
// language governing permissions and limitations under the
// License.
//
#if defined(__APPLE__)
#include <OpenGL/gl3.h>
#if defined(OSD_USES_GLEW)
#include <GL/glew.h>
#else
#include <OpenGL/gl3.h>
#endif
#define GLFW_INCLUDE_GL3
#define GLFW_NO_GLU
#else
@ -68,7 +40,7 @@
#endif
#if defined(GLFW_VERSION_3)
#include <GL/glfw3.h>
#include <GLFW/glfw3.h>
GLFWwindow* g_window=0;
GLFWmonitor* g_primary=0;
#else
@ -148,6 +120,7 @@ OpenSubdiv::OsdCpuComputeController *g_cpuComputeController = NULL;
#include "../common/stopwatch.h"
#include "../common/simple_math.h"
#include "../common/gl_hud.h"
#include "../common/patchColors.h"
static const char *shaderSource =
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
@ -175,6 +148,20 @@ enum KernelType { kCPU = 0,
kCL = 5,
kGLSL = 6,
kGLSLCompute = 7 };
enum DisplayStyle { kWire = 0,
kShaded,
kWireShaded,
kVaryingColor,
kFaceVaryingColor };
enum HudCheckBox { kHUD_CB_DISPLAY_CAGE_EDGES,
kHUD_CB_DISPLAY_CAGE_VERTS,
kHUD_CB_ANIMATE_VERTICES,
kHUD_CB_DISPLAY_PATCH_COLOR,
kHUD_CB_VIEW_LOD,
kHUD_CB_FRACTIONAL_SPACING,
kHUD_CB_PATCH_CULL,
kHUD_CB_FREEZE };
struct SimpleShape {
std::string name;
@ -191,16 +178,21 @@ std::vector<SimpleShape> g_defaultShapes;
int g_currentShape = 29;
int g_frame = 0,
g_freeze = 0,
g_repeatCount = 0;
// GUI variables
int g_fullscreen = 0,
g_freeze = 0,
g_wire = 1,
g_displayStyle = kShaded,
g_adaptive = 1,
g_mbutton[3] = {0, 0, 0},
g_running = 1;
int g_displayPatchColor = 0,
g_screenSpaceTess = 0,
g_fractionalSpacing = 0,
g_patchCull = 0;
float g_rotate[2] = {0, 0},
g_dolly = 5,
@ -400,8 +392,7 @@ linkDefaultProgram()
}
//------------------------------------------------------------------------------
static void
initializeShapes( ) {
static void initializeShapes( ) {
#include <shapes/catmark_cube_corner0.h>
g_defaultShapes.push_back(SimpleShape(catmark_cube_corner0, "catmark_cube_corner0", kCatmark));
@ -513,6 +504,33 @@ initializeShapes( ) {
#include <shapes/bilinear_cube.h>
g_defaultShapes.push_back(SimpleShape(bilinear_cube, "bilinear_cube", kBilinear));
/*
#include <shapes/loop_cube_creases0.h>
g_defaultShapes.push_back(SimpleShape(loop_cube_creases0, "loop_cube_creases0", kLoop));
#include <shapes/loop_cube_creases1.h>
g_defaultShapes.push_back(SimpleShape(loop_cube_creases1, "loop_cube_creases1", kLoop));
#include <shapes/loop_cube.h>
g_defaultShapes.push_back(SimpleShape(loop_cube, "loop_cube", kLoop));
#include <shapes/loop_icosahedron.h>
g_defaultShapes.push_back(SimpleShape(loop_icosahedron, "loop_icosahedron", kLoop));
#include <shapes/loop_saddle_edgecorner.h>
g_defaultShapes.push_back(SimpleShape(loop_saddle_edgecorner, "loop_saddle_edgecorner", kLoop));
#include <shapes/loop_saddle_edgeonly.h>
g_defaultShapes.push_back(SimpleShape(loop_saddle_edgeonly, "loop_saddle_edgeonly", kLoop));
#include <shapes/loop_triangle_edgecorner.h>
g_defaultShapes.push_back(SimpleShape(loop_triangle_edgecorner, "loop_triangle_edgecorner", kLoop));
#include <shapes/loop_triangle_edgeonly.h>
g_defaultShapes.push_back(SimpleShape(loop_triangle_edgeonly, "loop_triangle_edgeonly", kLoop));
*/
}
//------------------------------------------------------------------------------
@ -799,14 +817,25 @@ setSharpnessColor(float s, float *r, float *g, float *b)
}
//------------------------------------------------------------------------------
enum Effect {
kQuadWire = 0,
kQuadFill = 1,
kQuadLine = 2,
kTriWire = 3,
kTriFill = 4,
kTriLine = 5,
kPoint = 6,
union Effect {
Effect(int displayStyle_, int screenSpaceTess_, int fractionalSpacing_, int patchCull_) : value(0) {
displayStyle = displayStyle_;
screenSpaceTess = screenSpaceTess_;
fractionalSpacing = fractionalSpacing_;
patchCull = patchCull_;
}
struct {
unsigned int displayStyle:3;
unsigned int screenSpaceTess:1;
unsigned int fractionalSpacing:1;
unsigned int patchCull:1;
};
int value;
bool operator < (const Effect &e) const {
return value < e.value;
}
};
typedef std::pair<OpenSubdiv::OsdDrawContext::PatchDescriptor, Effect> EffectDesc;
@ -829,8 +858,7 @@ EffectDrawRegistry::_CreateDrawSourceConfig(DescType const & desc)
SourceConfigType * sconfig =
BaseRegistry::_CreateDrawSourceConfig(desc.first);
// sconfig->commonShader.AddDefine("OSD_ENABLE_PATCH_CULL");
// sconfig->commonShader.AddDefine("OSD_ENABLE_SCREENSPACE_TESSELLATION");
assert(sconfig);
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
const char *glslVersion = "#version 400\n";
@ -844,12 +872,8 @@ EffectDrawRegistry::_CreateDrawSourceConfig(DescType const & desc)
sconfig->vertexShader.version = glslVersion;
sconfig->vertexShader.AddDefine("VERTEX_SHADER");
} else {
if (effect == kQuadWire) effect = kTriWire;
if (effect == kQuadFill) effect = kTriFill;
if (effect == kQuadLine) effect = kTriLine;
sconfig->geometryShader.AddDefine("SMOOTH_NORMALS");
}
assert(sconfig);
sconfig->geometryShader.source = shaderSource;
sconfig->geometryShader.version = glslVersion;
@ -859,46 +883,55 @@ EffectDrawRegistry::_CreateDrawSourceConfig(DescType const & desc)
sconfig->fragmentShader.version = glslVersion;
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
switch (effect) {
case kQuadWire:
if (desc.first.GetType() == OpenSubdiv::FarPatchTables::QUADS) {
// uniform catmark, bilinear
sconfig->geometryShader.AddDefine("PRIM_QUAD");
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_WIRE");
sconfig->fragmentShader.AddDefine("PRIM_QUAD");
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_WIRE");
break;
case kQuadFill:
sconfig->geometryShader.AddDefine("PRIM_QUAD");
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_FILL");
sconfig->fragmentShader.AddDefine("PRIM_QUAD");
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_FILL");
break;
case kQuadLine:
sconfig->geometryShader.AddDefine("PRIM_QUAD");
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_LINE");
sconfig->fragmentShader.AddDefine("PRIM_QUAD");
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_LINE");
break;
case kTriWire:
sconfig->commonShader.AddDefine("UNIFORM_SUBDIVISION");
} else if (desc.first.GetType() == OpenSubdiv::FarPatchTables::TRIANGLES) {
// uniform loop
sconfig->geometryShader.AddDefine("PRIM_TRI");
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_WIRE");
sconfig->fragmentShader.AddDefine("PRIM_TRI");
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_WIRE");
break;
case kTriFill:
sconfig->commonShader.AddDefine("UNIFORM_SUBDIVISION");
} else {
// adaptive
sconfig->vertexShader.source = shaderSource + sconfig->vertexShader.source;
sconfig->tessControlShader.source = shaderSource + sconfig->tessControlShader.source;
sconfig->tessEvalShader.source = shaderSource + sconfig->tessEvalShader.source;
sconfig->geometryShader.AddDefine("PRIM_TRI");
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_FILL");
sconfig->fragmentShader.AddDefine("PRIM_TRI");
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_FILL");
}
if (effect.screenSpaceTess) {
sconfig->commonShader.AddDefine("OSD_ENABLE_SCREENSPACE_TESSELLATION");
}
if (effect.fractionalSpacing) {
sconfig->commonShader.AddDefine("OSD_FRACTIONAL_ODD_SPACING");
}
if (effect.patchCull) {
sconfig->commonShader.AddDefine("OSD_ENABLE_PATCH_CULL");
}
switch (effect.displayStyle) {
case kWire:
sconfig->commonShader.AddDefine("GEOMETRY_OUT_WIRE");
break;
case kTriLine:
sconfig->geometryShader.AddDefine("PRIM_TRI");
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_LINE");
sconfig->fragmentShader.AddDefine("PRIM_TRI");
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_LINE");
case kWireShaded:
sconfig->commonShader.AddDefine("GEOMETRY_OUT_LINE");
break;
case kPoint:
sconfig->geometryShader.AddDefine("PRIM_POINT");
sconfig->fragmentShader.AddDefine("PRIM_POINT");
case kShaded:
sconfig->commonShader.AddDefine("GEOMETRY_OUT_FILL");
break;
case kVaryingColor:
sconfig->commonShader.AddDefine("VARYING_COLOR");
sconfig->commonShader.AddDefine("GEOMETRY_OUT_FILL");
break;
case kFaceVaryingColor:
sconfig->commonShader.AddDefine("OSD_FVAR_WIDTH", "2");
sconfig->commonShader.AddDefine("FACEVARYING_COLOR");
sconfig->commonShader.AddDefine("GEOMETRY_OUT_FILL");
break;
}
@ -934,31 +967,37 @@ EffectDrawRegistry::_CreateDrawConfig(
GLint loc;
#if not defined(GL_ARB_separate_shader_objects) || defined(GL_VERSION_4_1)
glUseProgram(config->program);
if ((loc = glGetUniformLocation(config->program, "g_VertexBuffer")) != -1) {
if ((loc = glGetUniformLocation(config->program, "OsdVertexBuffer")) != -1) {
glUniform1i(loc, 0); // GL_TEXTURE0
}
if ((loc = glGetUniformLocation(config->program, "g_ValenceBuffer")) != -1) {
if ((loc = glGetUniformLocation(config->program, "OsdValenceBuffer")) != -1) {
glUniform1i(loc, 1); // GL_TEXTURE1
}
if ((loc = glGetUniformLocation(config->program, "g_QuadOffsetBuffer")) != -1) {
if ((loc = glGetUniformLocation(config->program, "OsdQuadOffsetBuffer")) != -1) {
glUniform1i(loc, 2); // GL_TEXTURE2
}
if ((loc = glGetUniformLocation(config->program, "g_ptexIndicesBuffer")) != -1) {
if ((loc = glGetUniformLocation(config->program, "OsdPatchParamBuffer")) != -1) {
glUniform1i(loc, 3); // GL_TEXTURE3
}
if ((loc = glGetUniformLocation(config->program, "OsdFVarDataBuffer")) != -1) {
glUniform1i(loc, 4); // GL_TEXTURE4
}
#else
if ((loc = glGetUniformLocation(config->program, "g_VertexBuffer")) != -1) {
if ((loc = glGetUniformLocation(config->program, "OsdVertexBuffer")) != -1) {
glProgramUniform1i(config->program, loc, 0); // GL_TEXTURE0
}
if ((loc = glGetUniformLocation(config->program, "g_ValenceBuffer")) != -1) {
if ((loc = glGetUniformLocation(config->program, "OsdValenceBuffer")) != -1) {
glProgramUniform1i(config->program, loc, 1); // GL_TEXTURE1
}
if ((loc = glGetUniformLocation(config->program, "g_QuadOffsetBuffer")) != -1) {
if ((loc = glGetUniformLocation(config->program, "OsdQuadOffsetBuffer")) != -1) {
glProgramUniform1i(config->program, loc, 2); // GL_TEXTURE2
}
if ((loc = glGetUniformLocation(config->program, "g_ptexIndicesBuffer")) != -1) {
if ((loc = glGetUniformLocation(config->program, "OsdPatchParamBuffer")) != -1) {
glProgramUniform1i(config->program, loc, 3); // GL_TEXTURE3
}
if ((loc = glGetUniformLocation(config->program, "OsdFVarDataBuffer")) != -1) {
glProgramUniform1i(config->program, loc, 4); // GL_TEXTURE4
}
#endif
return config;
@ -967,13 +1006,9 @@ EffectDrawRegistry::_CreateDrawConfig(
EffectDrawRegistry effectRegistry;
static Effect
GetEffect(Scheme scheme)
GetEffect()
{
if (scheme == kLoop) {
return (g_wire == 0 ? kTriWire : (g_wire == 1 ? kTriFill : kTriLine));
} else {
return (g_wire == 0 ? kQuadWire : (g_wire == 1 ? kQuadFill : kQuadLine));
}
return Effect(g_displayStyle, g_screenSpaceTess, g_fractionalSpacing, g_patchCull);
}
//------------------------------------------------------------------------------
@ -1113,24 +1148,41 @@ displayMesh(MeshData *pMesh) {
}
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
GLuint program = bindProgram(pMesh, GetEffect(pMesh->m_scheme), patch);
GLuint program = bindProgram(pMesh, GetEffect(), patch);
GLuint diffuseColor = glGetUniformLocation(program, "diffuseColor");
glProgramUniform4f(program, diffuseColor, 0.4f, 0.4f, 0.8f, 1);
GLuint uniformGregoryQuadOffset = glGetUniformLocation(program, "GregoryQuadOffsetBase");
GLuint uniformLevelBase = glGetUniformLocation(program, "LevelBase");
glProgramUniform1i(program, uniformGregoryQuadOffset, patch.GetQuadOffsetIndex());
glProgramUniform1i(program, uniformLevelBase, patch.GetPatchIndex());
if (g_displayPatchColor and primType == GL_PATCHES) {
float const * color = getAdaptivePatchColor( desc );
glProgramUniform4f(program, diffuseColor, color[0], color[1], color[2], color[3]);
} else {
glProgramUniform4f(program, diffuseColor, 0.4f, 0.4f, 0.8f, 1);
}
GLuint uniformGregoryQuadOffsetBase =
glGetUniformLocation(program, "OsdGregoryQuadOffsetBase");
GLuint uniformPrimitiveIdBase =
glGetUniformLocation(program, "OsdPrimitiveIdBase");
glProgramUniform1i(program, uniformGregoryQuadOffsetBase,
patch.GetQuadOffsetIndex());
glProgramUniform1i(program, uniformPrimitiveIdBase,
patch.GetPatchIndex());
#else
bindProgram(pMesh, GetEffect(), patch);
GLuint program = bindProgram(pMesh, GetEffect(), patch);
GLint uniformPrimitiveIdBase =
glGetUniformLocation(program, "OsdPrimitiveIdBase");
if (uniformPrimitiveIdBase != -1)
glUniform1i(uniformPrimitiveIdBase, patch.GetPatchIndex());
#endif
if (g_wire == 0) {
if (g_displayStyle == kWire) {
glDisable(GL_CULL_FACE);
}
glDrawElements(primType, patch.GetNumIndices(), GL_UNSIGNED_INT,
(void *)(patch.GetVertIndex() * sizeof(unsigned int)));
if (g_wire == 0) {
(void *)(patch.GetVertIndex() * sizeof(unsigned int)));
if (g_displayStyle == kWire) {
glEnable(GL_CULL_FACE);
}
}
@ -1242,7 +1294,7 @@ motion(int x, int y) {
//------------------------------------------------------------------------------
static void
#if GLFW_VERSION_MAJOR>=3
mouse(GLFWwindow *, int button, int state) {
mouse(GLFWwindow *, int button, int state, int mods) {
#else
mouse(int button, int state) {
#endif
@ -1341,8 +1393,9 @@ toggleFullScreen() {
//------------------------------------------------------------------------------
static void
#if GLFW_VERSION_MAJOR>=3
keyboard(GLFWwindow *, int key, int event) {
keyboard(GLFWwindow *, int key, int scancode, int event, int mods) {
#else
#define GLFW_KEY_ESCAPE GLFW_KEY_ESC
keyboard(int key, int event) {
#endif
@ -1356,7 +1409,7 @@ keyboard(int key, int event) {
case '+':
case '=': g_tessLevel++; break;
case '-': g_tessLevel = std::max(g_tessLevelMin, g_tessLevel-1); break;
case GLFW_KEY_ESC: g_hud.SetVisible(!g_hud.IsVisible()); break;
case GLFW_KEY_ESCAPE: g_hud.SetVisible(!g_hud.IsVisible()); break;
}
}
@ -1624,9 +1677,9 @@ int main(int argc, char ** argv)
}
if (g_primary) {
GLFWvidmode vidmode = glfwGetVideoMode(g_primary);
g_width = vidmode.width;
g_height = vidmode.height;
GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary);
g_width = vidmode->width;
g_height = vidmode->height;
}
}
@ -1658,7 +1711,7 @@ int main(int argc, char ** argv)
#endif
#if not defined(__APPLE__)
#if defined(OSD_USES_GLEW)
#ifdef CORE_PROFILE
// this is the only way to initialize glew correctly under core profile context.
glewExperimental = true;

View File

@ -246,12 +246,12 @@ OsdPtexTextureLoader::~OsdPtexTextureLoader()
ClearPages();
}
const unsigned long int
unsigned long int
OsdPtexTextureLoader::GetNumBlocks( ) const {
return (unsigned long int)_blocks.size();
}
const unsigned long int
unsigned long int
OsdPtexTextureLoader::GetNumPages( ) const {
return (unsigned long int)_pages.size();
}

View File

@ -91,13 +91,13 @@ public:
~OsdPtexTextureLoader();
const unsigned short GetPageSize( ) const {
unsigned short GetPageSize( ) const {
return _pagesize;
}
const unsigned long int GetNumBlocks( ) const;
unsigned long int GetNumBlocks( ) const;
const unsigned long int GetNumPages( ) const;
unsigned long int GetNumPages( ) const;
const unsigned int * GetIndexBuffer( ) const {
return _indexBuffer;