2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
|
|
// with the following modification; you may not use this file except in
|
|
|
|
// compliance with the Apache License and the following modification to it:
|
|
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// 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 to comply with Section 4(c) of
|
|
|
|
// the License and to reproduce the content of the NOTICE file.
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// You may obtain a copy of the Apache License at
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-18 21:19:50 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the Apache License with the above modification is
|
|
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
|
|
// language governing permissions and limitations under the Apache License.
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-09-26 19:04:57 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
#if defined(__APPLE__)
|
2013-06-26 07:52:57 +00:00
|
|
|
#if defined(OSD_USES_GLEW)
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#else
|
|
|
|
#include <OpenGL/gl3.h>
|
|
|
|
#endif
|
2013-01-29 23:54:18 +00:00
|
|
|
#define GLFW_INCLUDE_GL3
|
|
|
|
#define GLFW_NO_GLU
|
2012-08-04 02:51:27 +00:00
|
|
|
#else
|
2013-01-29 23:54:18 +00:00
|
|
|
#include <stdlib.h>
|
2012-08-04 02:51:27 +00:00
|
|
|
#include <GL/glew.h>
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
#include <GL/wglew.h>
|
|
|
|
#endif
|
2013-01-31 23:34:35 +00:00
|
|
|
#endif
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
GLFWwindow* g_window = 0;
|
|
|
|
GLFWmonitor* g_primary = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
2014-09-05 22:07:46 +00:00
|
|
|
#include <iostream>
|
2013-09-21 01:29:00 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/glDrawContext.h>
|
2014-12-04 01:19:07 +00:00
|
|
|
#include <far/error.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-09 00:31:26 +00:00
|
|
|
#include <osd/cpuEvaluator.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/cpuGLVertexBuffer.h>
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENMP
|
2015-05-09 00:31:26 +00:00
|
|
|
#include <osd/ompEvaluator.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-04-28 06:05:18 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_TBB
|
2015-05-09 00:31:26 +00:00
|
|
|
#include <osd/tbbEvaluator.h>
|
2014-05-01 03:53:37 +00:00
|
|
|
#endif
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2015-05-09 00:31:26 +00:00
|
|
|
#include <osd/clEvaluator.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/clGLVertexBuffer.h>
|
2015-04-28 22:46:37 +00:00
|
|
|
#include "../common/clDeviceContext.h"
|
|
|
|
CLDeviceContext g_clDeviceContext;
|
2012-08-04 02:51:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_CUDA
|
2015-05-09 00:31:26 +00:00
|
|
|
#include <osd/cudaEvaluator.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/cudaGLVertexBuffer.h>
|
2015-04-28 22:46:37 +00:00
|
|
|
#include "../common/cudaDeviceContext.h"
|
|
|
|
CudaDeviceContext g_cudaDeviceContext;
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
|
2015-05-09 00:31:26 +00:00
|
|
|
#include <osd/glXFBEvaluator.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/glVertexBuffer.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
|
2015-05-09 00:31:26 +00:00
|
|
|
#include <osd/glComputeEvaluator.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/glVertexBuffer.h>
|
2012-08-04 02:51:27 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/glMesh.h>
|
2014-09-05 22:07:46 +00:00
|
|
|
OpenSubdiv::Osd::GLMeshInterface *g_mesh;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
#include "Ptexture.h"
|
|
|
|
#include "PtexUtils.h"
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
#include <common/vtr_utils.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../common/stopwatch.h"
|
|
|
|
#include "../common/simple_math.h"
|
2015-05-19 01:04:38 +00:00
|
|
|
#include "../common/glHud.h"
|
|
|
|
#include "../common/glUtils.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../common/hdr_reader.h"
|
2015-05-07 20:56:48 +00:00
|
|
|
#include "../common/glPtexMipmapTexture.h"
|
2015-05-14 00:35:46 +00:00
|
|
|
#include "../common/glShaderCache.h"
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
#include <osd/glslPatchShaderSource.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
static const char *g_defaultShaderSource =
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
2014-01-04 00:59:26 +00:00
|
|
|
#include "shader.gen.h"
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
2014-01-04 00:59:26 +00:00
|
|
|
#include "shader_gl3.gen.h"
|
2013-01-29 23:54:18 +00:00
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
;
|
|
|
|
static const char *g_skyShaderSource =
|
2014-01-04 00:59:26 +00:00
|
|
|
#include "skyshader.gen.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
;
|
|
|
|
static std::string g_shaderSource;
|
|
|
|
static const char *g_shaderFilename = NULL;
|
|
|
|
|
|
|
|
enum KernelType { kCPU = 0,
|
|
|
|
kOPENMP = 1,
|
2014-04-28 06:05:18 +00:00
|
|
|
kTBB = 2,
|
|
|
|
kCUDA = 3,
|
|
|
|
kCL = 4,
|
|
|
|
kGLSL = 5,
|
2014-09-05 22:07:46 +00:00
|
|
|
kGLSLCompute = 6 };
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
enum HudCheckBox { HUD_CB_ADAPTIVE,
|
|
|
|
HUD_CB_DISPLAY_OCCLUSION,
|
|
|
|
HUD_CB_DISPLAY_NORMALMAP,
|
|
|
|
HUD_CB_DISPLAY_SPECULAR,
|
2013-11-08 18:47:11 +00:00
|
|
|
HUD_CB_CAGE_EDGES,
|
2012-12-11 01:15:13 +00:00
|
|
|
HUD_CB_ANIMATE_VERTICES,
|
|
|
|
HUD_CB_VIEW_LOD,
|
2013-06-27 20:34:25 +00:00
|
|
|
HUD_CB_FRACTIONAL_SPACING,
|
2012-12-11 01:15:13 +00:00
|
|
|
HUD_CB_PATCH_CULL,
|
2013-03-16 01:03:22 +00:00
|
|
|
HUD_CB_IBL,
|
2013-07-18 22:06:48 +00:00
|
|
|
HUD_CB_BLOOM,
|
2013-10-16 00:47:58 +00:00
|
|
|
HUD_CB_SEAMLESS_MIPMAP,
|
2013-07-18 22:06:48 +00:00
|
|
|
HUD_CB_FREEZE };
|
2013-09-21 01:29:00 +00:00
|
|
|
|
|
|
|
enum HudRadioGroup { HUD_RB_KERNEL,
|
|
|
|
HUD_RB_LEVEL,
|
|
|
|
HUD_RB_SCHEME,
|
|
|
|
HUD_RB_WIRE,
|
|
|
|
HUD_RB_COLOR,
|
|
|
|
HUD_RB_DISPLACEMENT,
|
|
|
|
HUD_RB_NORMAL };
|
|
|
|
|
|
|
|
enum DisplayType { DISPLAY_WIRE,
|
|
|
|
DISPLAY_SHADED,
|
|
|
|
DISPLAY_WIRE_ON_SHADED };
|
|
|
|
|
|
|
|
enum ColorType { COLOR_NONE,
|
|
|
|
COLOR_PTEX_NEAREST,
|
|
|
|
COLOR_PTEX_HW_BILINEAR,
|
|
|
|
COLOR_PTEX_BILINEAR,
|
|
|
|
COLOR_PTEX_BIQUADRATIC,
|
|
|
|
COLOR_PATCHTYPE,
|
|
|
|
COLOR_PATCHCOORD,
|
|
|
|
COLOR_NORMAL };
|
|
|
|
|
|
|
|
enum DisplacementType { DISPLACEMENT_NONE,
|
|
|
|
DISPLACEMENT_HW_BILINEAR,
|
|
|
|
DISPLACEMENT_BILINEAR,
|
|
|
|
DISPLACEMENT_BIQUADRATIC };
|
|
|
|
|
2013-09-26 16:31:54 +00:00
|
|
|
enum NormalType { NORMAL_SURFACE,
|
|
|
|
NORMAL_FACET,
|
2013-09-21 01:29:00 +00:00
|
|
|
NORMAL_HW_SCREENSPACE,
|
|
|
|
NORMAL_SCREENSPACE,
|
|
|
|
NORMAL_BIQUADRATIC,
|
|
|
|
NORMAL_BIQUADRATIC_WG };
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2012-08-04 02:51:27 +00:00
|
|
|
int g_frame = 0,
|
|
|
|
g_repeatCount = 0;
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
// GUI variables
|
2013-09-21 01:29:00 +00:00
|
|
|
int g_fullscreen = 0,
|
|
|
|
g_wire = DISPLAY_SHADED,
|
2012-08-04 02:51:27 +00:00
|
|
|
g_drawNormals = 0,
|
2013-11-08 18:47:11 +00:00
|
|
|
g_drawCageEdges = 0,
|
2012-08-04 02:51:27 +00:00
|
|
|
g_mbutton[3] = {0, 0, 0},
|
2014-09-05 22:07:46 +00:00
|
|
|
g_level = 1,
|
2012-12-11 01:15:13 +00:00
|
|
|
g_tessLevel = 2,
|
|
|
|
g_kernel = kCPU,
|
2012-08-04 02:51:27 +00:00
|
|
|
g_scheme = 0,
|
2013-09-21 01:29:00 +00:00
|
|
|
g_running = 1,
|
|
|
|
g_maxMipmapLevels = 10,
|
|
|
|
g_color = COLOR_PTEX_BILINEAR,
|
|
|
|
g_displacement = DISPLACEMENT_NONE,
|
2013-09-26 16:31:54 +00:00
|
|
|
g_normal = NORMAL_SURFACE;
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
float g_moveScale = 0.0f,
|
|
|
|
g_displacementScale = 1.0f,
|
2013-09-21 01:29:00 +00:00
|
|
|
g_mipmapBias = 0.0;
|
2013-03-16 01:03:22 +00:00
|
|
|
|
|
|
|
bool g_adaptive = false,
|
|
|
|
g_yup = false,
|
2012-12-11 01:15:13 +00:00
|
|
|
g_patchCull = true,
|
|
|
|
g_screenSpaceTess = true,
|
2013-09-21 01:29:00 +00:00
|
|
|
g_fractionalSpacing = true,
|
2013-03-16 01:03:22 +00:00
|
|
|
g_ibl = false,
|
2013-07-18 22:06:48 +00:00
|
|
|
g_bloom = false,
|
|
|
|
g_freeze = false;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
GLuint g_constantUB = 0,
|
|
|
|
g_constantBinding = 0;
|
2013-01-29 23:54:18 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
// ptex switch
|
2013-09-21 01:29:00 +00:00
|
|
|
bool g_occlusion = false,
|
2012-12-11 01:15:13 +00:00
|
|
|
g_specular = false;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-10-16 00:47:58 +00:00
|
|
|
bool g_seamless = true;
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
// camera
|
|
|
|
float g_rotate[2] = {0, 0},
|
|
|
|
g_dolly = 5,
|
|
|
|
g_pan[2] = {0, 0},
|
|
|
|
g_center[3] = {0, 0, 0},
|
|
|
|
g_size = 0;
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
int g_prev_x = 0,
|
|
|
|
g_prev_y = 0;
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
// viewport
|
2012-12-11 01:15:13 +00:00
|
|
|
int g_width = 1024,
|
|
|
|
g_height = 1024;
|
|
|
|
|
|
|
|
GLhud g_hud;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
// performance
|
|
|
|
float g_cpuTime = 0;
|
|
|
|
float g_gpuTime = 0;
|
2012-12-11 01:15:13 +00:00
|
|
|
#define NUM_FPS_TIME_SAMPLES 6
|
2013-09-21 01:29:00 +00:00
|
|
|
float g_fpsTimeSamples[NUM_FPS_TIME_SAMPLES] = {0, 0, 0, 0, 0, 0};
|
2012-12-11 01:15:13 +00:00
|
|
|
int g_currentFpsTimeSample = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
Stopwatch g_fpsTimer;
|
2013-03-16 01:03:22 +00:00
|
|
|
float g_animTime = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
// geometry
|
|
|
|
std::vector<float> g_positions,
|
|
|
|
g_normals;
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
std::vector<std::vector<float> > g_animPositions;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-05-15 17:26:23 +00:00
|
|
|
GLuint g_queries[2] = {0, 0};
|
2013-01-29 23:54:18 +00:00
|
|
|
GLuint g_vao = 0;
|
2013-11-08 18:47:11 +00:00
|
|
|
GLuint g_cageEdgeVAO = 0;
|
2013-01-29 23:54:18 +00:00
|
|
|
GLuint g_skyVAO = 0;
|
2013-11-08 18:47:11 +00:00
|
|
|
GLuint g_edgeIndexBuffer = 0;
|
|
|
|
GLuint g_numCageEdges = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
GLuint g_diffuseEnvironmentMap = 0;
|
|
|
|
GLuint g_specularEnvironmentMap = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
struct Sky {
|
|
|
|
int numIndices;
|
|
|
|
GLuint vertexBuffer;
|
|
|
|
GLuint elementBuffer;
|
|
|
|
GLuint mvpMatrix;
|
2015-05-14 00:35:46 +00:00
|
|
|
GLDrawConfig *drawConfig;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
Sky() : numIndices(0), vertexBuffer(0), elementBuffer(0), mvpMatrix(0),
|
2015-05-14 00:35:46 +00:00
|
|
|
drawConfig(NULL) {}
|
|
|
|
~Sky() {
|
|
|
|
delete drawConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BuildProgram(const char *source) {
|
|
|
|
if (drawConfig) delete drawConfig;
|
|
|
|
|
|
|
|
drawConfig = new GLDrawConfig("#version 410\n");
|
|
|
|
|
|
|
|
drawConfig->CompileAndAttachShader(GL_VERTEX_SHADER,
|
|
|
|
"#define SKY_VERTEX_SHADER\n" +
|
|
|
|
std::string(source));
|
|
|
|
drawConfig->CompileAndAttachShader(GL_FRAGMENT_SHADER,
|
|
|
|
"#define SKY_FRAGMENT_SHADER\n" +
|
|
|
|
std::string(source));
|
|
|
|
if (drawConfig->Link() == false) {
|
|
|
|
delete drawConfig;
|
|
|
|
drawConfig = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-16 01:03:22 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
int GetProgram() const {
|
|
|
|
if (drawConfig) return drawConfig->GetProgram();
|
|
|
|
return 0;
|
2013-03-16 01:03:22 +00:00
|
|
|
}
|
2015-05-14 00:35:46 +00:00
|
|
|
|
|
|
|
} g_sky;
|
2013-03-16 01:03:22 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-05-07 20:56:48 +00:00
|
|
|
GLPtexMipmapTexture * g_osdPTexImage = 0;
|
|
|
|
GLPtexMipmapTexture * g_osdPTexDisplacement = 0;
|
|
|
|
GLPtexMipmapTexture * g_osdPTexOcclusion = 0;
|
|
|
|
GLPtexMipmapTexture * g_osdPTexSpecular = 0;
|
2012-12-11 01:15:13 +00:00
|
|
|
const char * g_ptexColorFilename;
|
2013-10-08 02:06:40 +00:00
|
|
|
size_t g_ptexMemoryUsage = 0;
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
checkGLErrors(std::string const & where = "") {
|
2012-12-11 01:15:13 +00:00
|
|
|
GLuint err;
|
|
|
|
while ((err = glGetError()) != GL_NO_ERROR) {
|
|
|
|
std::cerr << "GL error: "
|
|
|
|
<< (where.empty() ? "" : where + " ")
|
|
|
|
<< err << "\n";
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
2013-01-29 23:54:18 +00:00
|
|
|
}
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
calcNormals(OpenSubdiv::Far::TopologyRefiner * refiner,
|
|
|
|
std::vector<float> const & pos, std::vector<float> & result ) {
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
typedef OpenSubdiv::Far::ConstIndexArray IndexArray;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
// calc normal vectors
|
2014-09-05 22:07:46 +00:00
|
|
|
int nverts = refiner->GetNumVertices(0),
|
|
|
|
nfaces = refiner->GetNumFaces(0);
|
|
|
|
|
|
|
|
for (int face = 0; face < nfaces; ++face) {
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
IndexArray fverts = refiner->GetFaceVertices(0, face);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
float const * p0 = &pos[fverts[0]*3],
|
|
|
|
* p1 = &pos[fverts[1]*3],
|
|
|
|
* p2 = &pos[fverts[2]*3];
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
float n[3];
|
2013-09-21 01:29:00 +00:00
|
|
|
cross(n, p0, p1, p2);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int vert = 0; vert < fverts.size(); ++vert) {
|
|
|
|
int idx = fverts[vert] * 3;
|
2012-08-04 02:51:27 +00:00
|
|
|
result[idx ] += n[0];
|
|
|
|
result[idx+1] += n[1];
|
|
|
|
result[idx+2] += n[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < nverts; ++i)
|
2013-09-21 01:29:00 +00:00
|
|
|
normalize(&result[i*3]);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
updateGeom() {
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
int nverts = (int)g_positions.size() / 3;
|
|
|
|
|
2013-03-18 18:56:09 +00:00
|
|
|
if (g_moveScale and g_adaptive and not g_animPositions.empty()) {
|
2012-12-11 01:15:13 +00:00
|
|
|
// baked animation only works with adaptive for now
|
|
|
|
// (since non-adaptive requires normals)
|
2013-03-16 01:03:22 +00:00
|
|
|
int nkey = (int)g_animPositions.size();
|
2013-03-18 18:56:09 +00:00
|
|
|
const float fps = 24.0f;
|
2013-03-16 01:03:22 +00:00
|
|
|
|
2013-03-18 18:56:09 +00:00
|
|
|
float p = fmodf(g_animTime * fps, (float)nkey);
|
2013-03-16 01:03:22 +00:00
|
|
|
int key = (int)p;
|
2013-03-18 18:56:09 +00:00
|
|
|
float b = p - key;
|
2013-03-16 01:03:22 +00:00
|
|
|
|
|
|
|
std::vector<float> vertex;
|
|
|
|
vertex.reserve(nverts*3);
|
|
|
|
for (int i = 0; i < nverts*3; ++i) {
|
|
|
|
float p0 = g_animPositions[key][i];
|
|
|
|
float p1 = g_animPositions[(key+1)%nkey][i];
|
|
|
|
vertex.push_back(p0*(1-b) + p1*b);
|
|
|
|
}
|
|
|
|
g_mesh->UpdateVertexBuffer(&vertex[0], 0, nverts);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
} else {
|
|
|
|
std::vector<float> vertex;
|
|
|
|
vertex.reserve(nverts*6);
|
|
|
|
|
|
|
|
const float *p = &g_positions[0];
|
|
|
|
const float *n = &g_normals[0];
|
|
|
|
|
|
|
|
for (int i = 0; i < nverts; ++i) {
|
|
|
|
float move = g_size*0.005f*cosf(p[0]*100/g_size+g_frame*0.01f);
|
|
|
|
vertex.push_back(p[0]);
|
|
|
|
vertex.push_back(p[1]+g_moveScale*move);
|
|
|
|
vertex.push_back(p[2]);
|
|
|
|
p += 3;
|
|
|
|
if (g_adaptive == false) {
|
|
|
|
vertex.push_back(n[0]);
|
|
|
|
vertex.push_back(n[1]);
|
|
|
|
vertex.push_back(n[2]);
|
|
|
|
n += 3;
|
|
|
|
}
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-08 01:50:15 +00:00
|
|
|
g_mesh->UpdateVertexBuffer(&vertex[0], 0, nverts);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Stopwatch s;
|
|
|
|
s.Start();
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
g_mesh->Refine();
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
s.Stop();
|
|
|
|
g_cpuTime = float(s.GetElapsed() * 1000.0f);
|
|
|
|
s.Start();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
g_mesh->Synchronize();
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
s.Stop();
|
|
|
|
g_gpuTime = float(s.GetElapsed() * 1000.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
fitFrame() {
|
2012-08-04 02:51:27 +00:00
|
|
|
g_pan[0] = g_pan[1] = 0;
|
|
|
|
g_dolly = g_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2014-09-05 22:07:46 +00:00
|
|
|
Shape *
|
|
|
|
createPTexGeo(PtexTexture * r) {
|
|
|
|
|
|
|
|
PtexMetaData* meta = r->getMetaData();
|
|
|
|
|
|
|
|
if (meta->numKeys() < 3) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
float const * vp;
|
|
|
|
int const *vi, *vc;
|
|
|
|
int nvp, nvi, nvc;
|
|
|
|
|
|
|
|
meta->getValue("PtexFaceVertCounts", vc, nvc);
|
|
|
|
if (nvc == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
meta->getValue("PtexVertPositions", vp, nvp);
|
|
|
|
if (nvp == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
meta->getValue("PtexFaceVertIndices", vi, nvi);
|
|
|
|
if (nvi == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Shape * shape = new Shape;
|
|
|
|
|
|
|
|
shape->scheme = kCatmark;
|
|
|
|
|
|
|
|
shape->verts.resize(nvp);
|
|
|
|
for (int i=0; i<nvp; ++i) {
|
|
|
|
shape->verts[i] = vp[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
shape->nvertsPerFace.resize(nvc);
|
|
|
|
for (int i=0; i<nvc; ++i) {
|
|
|
|
shape->nvertsPerFace[i] = vc[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
shape->faceverts.resize(nvi);
|
|
|
|
for (int i=0; i<nvi; ++i) {
|
|
|
|
shape->faceverts[i] = vi[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
// compute model bounding
|
|
|
|
float min[3] = {vp[0], vp[1], vp[2]};
|
|
|
|
float max[3] = {vp[0], vp[1], vp[2]};
|
|
|
|
for (int i = 0; i < nvp/3; ++i) {
|
|
|
|
for (int j = 0; j < 3; ++j) {
|
|
|
|
float v = vp[i*3+j];
|
|
|
|
min[j] = std::min(min[j], v);
|
|
|
|
max[j] = std::max(max[j], v);
|
|
|
|
}
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
for (int j = 0; j < 3; ++j) {
|
|
|
|
g_center[j] = (min[j] + max[j]) * 0.5f;
|
|
|
|
g_size += (max[j]-min[j])*(max[j]-min[j]);
|
|
|
|
}
|
|
|
|
g_size = sqrtf(g_size);
|
|
|
|
|
|
|
|
return shape;
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
reshape(GLFWwindow *, int width, int height) {
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
g_width = width;
|
|
|
|
g_height = height;
|
|
|
|
|
2014-02-22 03:25:00 +00:00
|
|
|
int windowWidth = g_width, windowHeight = g_height;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-02-22 03:25:00 +00:00
|
|
|
// window size might not match framebuffer size on a high DPI display
|
|
|
|
glfwGetWindowSize(g_window, &windowWidth, &windowHeight);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-24 18:15:19 +00:00
|
|
|
g_hud.Rebuild(windowWidth, windowHeight, width, height);
|
2013-03-16 01:03:22 +00:00
|
|
|
|
|
|
|
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
2013-09-21 01:29:00 +00:00
|
|
|
if (status != GL_FRAMEBUFFER_COMPLETE)
|
2013-03-16 01:03:22 +00:00
|
|
|
assert(false);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
|
|
|
|
checkGLErrors("Reshape");
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
void reshape() {
|
|
|
|
reshape(g_window, g_width, g_height);
|
|
|
|
}
|
2013-03-19 21:31:44 +00:00
|
|
|
|
|
|
|
void windowClose(GLFWwindow*) {
|
|
|
|
g_running = false;
|
|
|
|
}
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2014-09-05 22:07:46 +00:00
|
|
|
const char *getKernelName(int kernel) {
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (kernel == kCPU)
|
2012-08-04 02:51:27 +00:00
|
|
|
return "CPU";
|
2012-12-11 01:15:13 +00:00
|
|
|
else if (kernel == kOPENMP)
|
2012-08-04 02:51:27 +00:00
|
|
|
return "OpenMP";
|
2012-12-11 01:15:13 +00:00
|
|
|
else if (kernel == kCUDA)
|
2012-08-04 02:51:27 +00:00
|
|
|
return "Cuda";
|
2012-12-11 01:15:13 +00:00
|
|
|
else if (kernel == kGLSL)
|
2012-08-04 02:51:27 +00:00
|
|
|
return "GLSL";
|
2012-12-11 01:15:13 +00:00
|
|
|
else if (kernel == kCL)
|
2012-08-04 02:51:27 +00:00
|
|
|
return "OpenCL";
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
union Effect {
|
|
|
|
struct {
|
2013-09-21 01:29:00 +00:00
|
|
|
unsigned int wire:2;
|
|
|
|
unsigned int color:3;
|
|
|
|
unsigned int displacement:2;
|
|
|
|
unsigned int normal:3;
|
2012-12-11 01:15:13 +00:00
|
|
|
int occlusion:1;
|
|
|
|
int specular:1;
|
|
|
|
int patchCull:1;
|
|
|
|
int screenSpaceTess:1;
|
2013-06-27 20:34:25 +00:00
|
|
|
int fractionalSpacing:1;
|
2012-12-11 01:15:13 +00:00
|
|
|
int ibl:1;
|
2013-10-16 00:47:58 +00:00
|
|
|
int seamless:1;
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
|
|
|
int value;
|
|
|
|
|
|
|
|
bool operator < (const Effect &e) const {
|
|
|
|
return value < e.value;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-12 01:06:46 +00:00
|
|
|
struct EffectDesc {
|
|
|
|
EffectDesc(OpenSubdiv::Far::PatchDescriptor desc,
|
|
|
|
Effect effect) : desc(desc), effect(effect),
|
|
|
|
maxValence(0), numElements(0) { }
|
|
|
|
|
|
|
|
OpenSubdiv::Far::PatchDescriptor desc;
|
|
|
|
Effect effect;
|
|
|
|
int maxValence;
|
|
|
|
int numElements;
|
|
|
|
|
|
|
|
bool operator < (const EffectDesc &e) const {
|
|
|
|
return desc < e.desc || (desc == e.desc &&
|
|
|
|
(maxValence < e.maxValence || ((maxValence == e.maxValence) &&
|
|
|
|
(effect < e.effect))));
|
|
|
|
}
|
|
|
|
};
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2015-05-14 00:35:46 +00:00
|
|
|
class ShaderCache : public GLShaderCache<EffectDesc> {
|
|
|
|
public:
|
|
|
|
virtual GLDrawConfig *CreateDrawConfig(EffectDesc const &effectDesc) {
|
2015-05-07 20:56:48 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
using namespace OpenSubdiv;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// compile shader program
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
2015-05-14 00:35:46 +00:00
|
|
|
const char *glslVersion = "#version 400\n";
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
2015-05-14 00:35:46 +00:00
|
|
|
const char *glslVersion = "#version 330\n";
|
2013-01-29 23:54:18 +00:00
|
|
|
#endif
|
2015-05-14 00:35:46 +00:00
|
|
|
GLDrawConfig *config = new GLDrawConfig(glslVersion);
|
2013-01-29 23:54:18 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
Far::PatchDescriptor::Type type = effectDesc.desc.GetType();
|
2015-05-12 01:06:46 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// common defines
|
|
|
|
std::stringstream ss;
|
2015-05-12 01:06:46 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
if (type == Far::PatchDescriptor::QUADS) {
|
|
|
|
ss << "#define PRIM_QUAD\n";
|
|
|
|
} else if (type == Far::PatchDescriptor::LINES) {
|
|
|
|
ss << "#define PRIM_LINE\n";
|
|
|
|
} else {
|
|
|
|
ss << "#define PRIM_TRI\n";
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// OSD tessellation controls
|
|
|
|
if (effectDesc.effect.screenSpaceTess) {
|
|
|
|
ss << "#define OSD_ENABLE_SCREENSPACE_TESSELLATION\n";
|
|
|
|
}
|
|
|
|
if (effectDesc.effect.fractionalSpacing) {
|
|
|
|
ss << "#define OSD_FRACTIONAL_ODD_SPACING\n";
|
|
|
|
}
|
|
|
|
if (effectDesc.effect.patchCull) {
|
|
|
|
ss << "#define OSD_ENABLE_PATCH_CULL\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// for legacy gregory
|
|
|
|
ss << "#define OSD_MAX_VALENCE " << effectDesc.maxValence << "\n";
|
|
|
|
ss << "#define OSD_NUM_ELEMENTS " << effectDesc.numElements << "\n";
|
|
|
|
|
|
|
|
// add ptex functions
|
|
|
|
ss << GLPtexMipmapTexture::GetShaderSource();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// -------------------------------------------------------------
|
|
|
|
// display styles
|
|
|
|
// -------------------------------------------------------------
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// mipmap
|
|
|
|
if (effectDesc.effect.seamless) {
|
|
|
|
ss << "#define SEAMLESS_MIPMAP\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// wire
|
|
|
|
if (effectDesc.effect.wire == 0) {
|
|
|
|
ss << "#define GEOMETRY_OUT_WIRE\n";
|
|
|
|
} else if (effectDesc.effect.wire == 1) {
|
|
|
|
ss << "#define GEOMETRY_OUT_FILL\n";
|
|
|
|
} else if (effectDesc.effect.wire == 2) {
|
|
|
|
ss << "#define GEOMETRY_OUT_LINE\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// color
|
|
|
|
switch(effectDesc.effect.color) {
|
2013-11-20 23:47:59 +00:00
|
|
|
case COLOR_NONE:
|
|
|
|
break;
|
|
|
|
case COLOR_PTEX_NEAREST:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define COLOR_PTEX_NEAREST\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case COLOR_PTEX_HW_BILINEAR:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define COLOR_PTEX_HW_BILINEAR\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case COLOR_PTEX_BILINEAR:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define COLOR_PTEX_BILINEAR\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case COLOR_PTEX_BIQUADRATIC:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define COLOR_PTEX_BIQUADRATIC\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case COLOR_PATCHTYPE:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define COLOR_PATCHTYPE\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case COLOR_PATCHCOORD:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define COLOR_PATCHCOORD\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case COLOR_NORMAL:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define COLOR_NORMAL\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
2015-05-14 00:35:46 +00:00
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// displacement
|
|
|
|
switch (effectDesc.effect.displacement) {
|
2013-11-20 23:47:59 +00:00
|
|
|
case DISPLACEMENT_NONE:
|
|
|
|
break;
|
|
|
|
case DISPLACEMENT_HW_BILINEAR:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define DISPLACEMENT_HW_BILINEAR\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case DISPLACEMENT_BILINEAR:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define DISPLACEMENT_BILINEAR\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case DISPLACEMENT_BIQUADRATIC:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define DISPLACEMENT_BIQUADRATIC\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
2015-05-14 00:35:46 +00:00
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// normal
|
|
|
|
switch (effectDesc.effect.normal) {
|
2013-11-20 23:47:59 +00:00
|
|
|
case NORMAL_FACET:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define NORMAL_FACET\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case NORMAL_HW_SCREENSPACE:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define NORMAL_HW_SCREENSPACE\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case NORMAL_SCREENSPACE:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define NORMAL_SCREENSPACE\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case NORMAL_BIQUADRATIC:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define NORMAL_BIQUADRATIC\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
|
|
|
case NORMAL_BIQUADRATIC_WG:
|
2015-05-14 00:35:46 +00:00
|
|
|
ss << "#define OSD_COMPUTE_NORMAL_DERIVATIVES\n";
|
|
|
|
ss << "#define NORMAL_BIQUADRATIC_WG\n";
|
2013-11-20 23:47:59 +00:00
|
|
|
break;
|
2015-05-14 00:35:46 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// occlusion
|
|
|
|
if (effectDesc.effect.occlusion)
|
|
|
|
ss << "#define USE_PTEX_OCCLUSION\n";
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// specular
|
|
|
|
if (effectDesc.effect.specular)
|
|
|
|
ss << "#define USE_PTEX_SPECULAR\n";
|
2013-10-16 00:47:58 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// IBL
|
|
|
|
if (effectDesc.effect.ibl)
|
|
|
|
ss << "#define USE_IBL\n";
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// need for patch color-coding : we need these defines in the fragment shader
|
|
|
|
if (type == Far::PatchDescriptor::GREGORY) {
|
|
|
|
ss << "#define OSD_PATCH_GREGORY\n";
|
|
|
|
} else if (type == Far::PatchDescriptor::GREGORY_BOUNDARY) {
|
|
|
|
ss << "#define OSD_PATCH_GREGORY_BOUNDARY\n";
|
|
|
|
} else if (type == Far::PatchDescriptor::GREGORY_BASIS) {
|
|
|
|
ss << "#define OSD_PATCH_GREGORY_BASIS\n";
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// include osd PatchCommon
|
|
|
|
ss << Osd::GLSLPatchShaderSource::GetCommonShaderSource();
|
|
|
|
std::string common = ss.str();
|
|
|
|
ss.str("");
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// vertex shader
|
|
|
|
ss << common
|
|
|
|
// enable local vertex shader
|
|
|
|
<< (effectDesc.desc.IsAdaptive() ? "" : "#define VERTEX_SHADER\n")
|
|
|
|
<< g_shaderSource
|
|
|
|
<< Osd::GLSLPatchShaderSource::GetVertexShaderSource(type);
|
|
|
|
config->CompileAndAttachShader(GL_VERTEX_SHADER, ss.str());
|
|
|
|
ss.str("");
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
if (effectDesc.desc.IsAdaptive()) {
|
|
|
|
// tess control shader
|
|
|
|
ss << common
|
|
|
|
<< g_shaderSource
|
|
|
|
<< Osd::GLSLPatchShaderSource::GetTessControlShaderSource(type);
|
|
|
|
config->CompileAndAttachShader(GL_TESS_CONTROL_SHADER, ss.str());
|
|
|
|
ss.str("");
|
|
|
|
|
|
|
|
// tess eval shader
|
|
|
|
ss << common
|
|
|
|
<< g_shaderSource
|
|
|
|
<< Osd::GLSLPatchShaderSource::GetTessEvalShaderSource(type);
|
|
|
|
config->CompileAndAttachShader(GL_TESS_EVALUATION_SHADER, ss.str());
|
|
|
|
ss.str("");
|
|
|
|
}
|
2013-01-29 23:54:18 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// geometry shader
|
|
|
|
ss << common
|
|
|
|
<< "#define GEOMETRY_SHADER\n" // enable local geometry shader
|
|
|
|
<< g_shaderSource;
|
|
|
|
config->CompileAndAttachShader(GL_GEOMETRY_SHADER, ss.str());
|
|
|
|
ss.str("");
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// fragment shader
|
|
|
|
ss << common
|
|
|
|
<< "#define FRAGMENT_SHADER\n" // enable local fragment shader
|
|
|
|
<< g_shaderSource;
|
|
|
|
config->CompileAndAttachShader(GL_FRAGMENT_SHADER, ss.str());
|
|
|
|
ss.str("");
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
if (!config->Link()) {
|
|
|
|
delete config;
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// assign uniform locations
|
|
|
|
GLuint program = config->GetProgram();
|
|
|
|
GLuint uboIndex = glGetUniformBlockIndex(program, "Constant");
|
|
|
|
if (uboIndex != GL_INVALID_INDEX)
|
|
|
|
glUniformBlockBinding(program, uboIndex, g_constantBinding);
|
|
|
|
|
|
|
|
// assign texture locations
|
|
|
|
GLint loc;
|
|
|
|
// patch textures
|
|
|
|
glUseProgram(program);
|
|
|
|
if ((loc = glGetUniformLocation(program, "OsdVertexBuffer")) != -1) {
|
|
|
|
glUniform1i(loc, 0); // GL_TEXTURE0
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "OsdValenceBuffer")) != -1) {
|
|
|
|
glUniform1i(loc, 1); // GL_TEXTURE1
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "OsdQuadOffsetBuffer")) != -1) {
|
|
|
|
glUniform1i(loc, 2); // GL_TEXTURE2
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "OsdPatchParamBuffer")) != -1) {
|
|
|
|
glUniform1i(loc, 3); // GL_TEXTURE3
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// environment textures
|
|
|
|
if ((loc = glGetUniformLocation(program, "diffuseEnvironmentMap")) != -1) {
|
|
|
|
glUniform1i(loc, 5);
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "specularEnvironmentMap")) != -1) {
|
|
|
|
glUniform1i(loc, 6);
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// ptex textures
|
|
|
|
if ((loc = glGetUniformLocation(program, "textureImage_Data")) != -1) {
|
|
|
|
glUniform1i(loc, 7);
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "textureImage_Packing")) != -1) {
|
|
|
|
glUniform1i(loc, 8);
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "textureDisplace_Data")) != -1) {
|
|
|
|
glUniform1i(loc, 9);
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "textureDisplace_Packing")) != -1) {
|
|
|
|
glUniform1i(loc, 10);
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "textureOcclusion_Data")) != -1) {
|
|
|
|
glUniform1i(loc, 11);
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "textureOcclusion_Packing")) != -1) {
|
|
|
|
glUniform1i(loc, 12);
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "textureSpecular_Data")) != -1) {
|
|
|
|
glUniform1i(loc, 13);
|
|
|
|
}
|
|
|
|
if ((loc = glGetUniformLocation(program, "textureSpecular_Packing")) != -1) {
|
|
|
|
glUniform1i(loc, 14);
|
|
|
|
}
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
glUseProgram(0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
return config;
|
2015-05-12 01:06:46 +00:00
|
|
|
}
|
2015-05-14 00:35:46 +00:00
|
|
|
};
|
2015-05-12 01:06:46 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
ShaderCache g_shaderCache;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2015-05-07 20:56:48 +00:00
|
|
|
GLPtexMipmapTexture *
|
2014-09-05 22:07:46 +00:00
|
|
|
createPtex(const char *filename, int memLimit) {
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
Ptex::String ptexError;
|
|
|
|
printf("Loading ptex : %s\n", filename);
|
2013-09-26 16:31:54 +00:00
|
|
|
|
|
|
|
#define USE_PTEX_CACHE
|
|
|
|
#define PTEX_CACHE_SIZE (512*1024*1024)
|
|
|
|
|
|
|
|
#ifdef USE_PTEX_CACHE
|
|
|
|
PtexCache *cache = PtexCache::create(1, PTEX_CACHE_SIZE);
|
|
|
|
PtexTexture *ptex = cache->get(filename, ptexError);
|
|
|
|
#else
|
2012-12-11 01:15:13 +00:00
|
|
|
PtexTexture *ptex = PtexTexture::open(filename, ptexError, true);
|
2013-09-26 16:31:54 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (ptex == NULL) {
|
2013-01-22 22:47:46 +00:00
|
|
|
printf("Error in reading %s\n", filename);
|
2012-12-11 01:15:13 +00:00
|
|
|
exit(1);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
2013-10-08 02:06:40 +00:00
|
|
|
|
|
|
|
size_t targetMemory = memLimit * 1024 * 1024; // MB
|
|
|
|
|
2015-05-07 20:56:48 +00:00
|
|
|
GLPtexMipmapTexture *osdPtex = GLPtexMipmapTexture::Create(
|
|
|
|
ptex, g_maxMipmapLevels, targetMemory);
|
2013-10-08 02:06:40 +00:00
|
|
|
|
|
|
|
GLuint texture = osdPtex->GetTexelsTexture();
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, texture);
|
|
|
|
GLint w, h, d;
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_WIDTH, &w);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_HEIGHT, &h);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D_ARRAY, 0, GL_TEXTURE_DEPTH, &d);
|
|
|
|
printf("PageSize = %d x %d x %d\n", w, h, d);
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-28 17:23:55 +00:00
|
|
|
ptex->release();
|
|
|
|
|
2013-09-26 16:31:54 +00:00
|
|
|
#ifdef USE_PTEX_CACHE
|
|
|
|
cache->release();
|
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
return osdPtex;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
createOsdMesh(int level, int kernel) {
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
checkGLErrors("createOsdMesh");
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
Ptex::String ptexError;
|
2012-12-11 01:15:13 +00:00
|
|
|
PtexTexture *ptexColor = PtexTexture::open(g_ptexColorFilename, ptexError, true);
|
|
|
|
if (ptexColor == NULL) {
|
|
|
|
printf("Error in reading %s\n", g_ptexColorFilename);
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
// generate Shape representation from ptex
|
|
|
|
Shape * shape = createPTexGeo(ptexColor);
|
|
|
|
if (not shape) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_positions=shape->verts;
|
|
|
|
|
2014-12-15 18:23:13 +00:00
|
|
|
typedef OpenSubdiv::Far::ConstIndexArray IndexArray;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// create Vtr mesh (topology)
|
2015-01-07 01:40:11 +00:00
|
|
|
OpenSubdiv::Sdc::SchemeType sdctype = GetSdcType(*shape);
|
2014-09-05 22:07:46 +00:00
|
|
|
OpenSubdiv::Sdc::Options sdcoptions = GetSdcOptions(*shape);
|
|
|
|
|
|
|
|
OpenSubdiv::Far::TopologyRefiner * refiner =
|
2015-01-06 08:03:21 +00:00
|
|
|
OpenSubdiv::Far::TopologyRefinerFactory<Shape>::Create(*shape,
|
|
|
|
OpenSubdiv::Far::TopologyRefinerFactory<Shape>::Options(sdctype, sdcoptions));
|
2014-09-05 22:07:46 +00:00
|
|
|
|
|
|
|
// save coarse topology (used for coarse mesh drawing)
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-11-08 18:47:11 +00:00
|
|
|
// create cage edge index
|
2014-09-05 22:07:46 +00:00
|
|
|
int nedges = refiner->GetNumEdges(0);
|
|
|
|
std::vector<int> edgeIndices(nedges*2);
|
|
|
|
for(int i=0; i<nedges; ++i) {
|
|
|
|
IndexArray verts = refiner->GetEdgeVertices(0, i);
|
|
|
|
edgeIndices[i*2 ]=verts[0];
|
|
|
|
edgeIndices[i*2+1]=verts[1];
|
2013-11-08 18:47:11 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
delete shape;
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
g_normals.resize(g_positions.size(), 0.0f);
|
2014-09-05 22:07:46 +00:00
|
|
|
calcNormals(refiner, g_positions, g_normals);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
delete g_mesh;
|
|
|
|
g_mesh = NULL;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// Adaptive refinement currently supported only for catmull-clark scheme
|
2013-09-21 01:29:00 +00:00
|
|
|
bool doAdaptive = (g_adaptive != 0 and g_scheme == 0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
OpenSubdiv::Osd::MeshBitset bits;
|
|
|
|
bits.set(OpenSubdiv::Osd::MeshAdaptive, doAdaptive);
|
2015-04-18 00:36:55 +00:00
|
|
|
bits.set(OpenSubdiv::Osd::MeshEndCapGregoryBasis, true);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
int numVertexElements = g_adaptive ? 3 : 6;
|
2013-06-27 19:57:21 +00:00
|
|
|
int numVaryingElements = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (kernel == kCPU) {
|
2014-09-05 22:07:46 +00:00
|
|
|
g_mesh = new OpenSubdiv::Osd::Mesh<OpenSubdiv::Osd::CpuGLVertexBuffer,
|
2015-05-09 00:31:26 +00:00
|
|
|
OpenSubdiv::Far::StencilTables,
|
|
|
|
OpenSubdiv::Osd::CpuEvaluator,
|
|
|
|
OpenSubdiv::Osd::GLDrawContext>(
|
2014-09-05 22:07:46 +00:00
|
|
|
refiner,
|
2013-06-27 19:57:21 +00:00
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENMP
|
|
|
|
} else if (kernel == kOPENMP) {
|
2014-09-05 22:07:46 +00:00
|
|
|
g_mesh = new OpenSubdiv::Osd::Mesh<OpenSubdiv::Osd::CpuGLVertexBuffer,
|
2015-05-09 00:31:26 +00:00
|
|
|
OpenSubdiv::Far::StencilTables,
|
|
|
|
OpenSubdiv::Osd::OmpEvaluator,
|
|
|
|
OpenSubdiv::Osd::GLDrawContext>(
|
2014-09-05 22:07:46 +00:00
|
|
|
refiner,
|
2013-06-27 19:57:21 +00:00
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
2014-04-28 06:05:18 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_TBB
|
|
|
|
} else if (kernel == kTBB) {
|
2014-09-05 22:07:46 +00:00
|
|
|
g_mesh = new OpenSubdiv::Osd::Mesh<OpenSubdiv::Osd::CpuGLVertexBuffer,
|
2015-05-09 00:31:26 +00:00
|
|
|
OpenSubdiv::Far::StencilTables,
|
|
|
|
OpenSubdiv::Osd::TbbEvaluator,
|
|
|
|
OpenSubdiv::Osd::GLDrawContext>(
|
2014-09-05 22:07:46 +00:00
|
|
|
refiner,
|
2014-05-01 03:53:37 +00:00
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits);
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2013-09-21 01:29:00 +00:00
|
|
|
} else if (kernel == kCL) {
|
2015-05-09 00:31:26 +00:00
|
|
|
static OpenSubdiv::Osd::EvaluatorCacheT<OpenSubdiv::Osd::CLEvaluator> clEvaluatorCache;
|
2014-09-05 22:07:46 +00:00
|
|
|
g_mesh = new OpenSubdiv::Osd::Mesh<OpenSubdiv::Osd::CLGLVertexBuffer,
|
2015-05-09 00:31:26 +00:00
|
|
|
OpenSubdiv::Osd::CLStencilTables,
|
|
|
|
OpenSubdiv::Osd::CLEvaluator,
|
|
|
|
OpenSubdiv::Osd::GLDrawContext,
|
|
|
|
CLDeviceContext>(
|
2014-09-05 22:07:46 +00:00
|
|
|
refiner,
|
2013-06-27 19:57:21 +00:00
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
2015-05-09 00:31:26 +00:00
|
|
|
level, bits,
|
|
|
|
&clEvaluatorCache,
|
|
|
|
&g_clDeviceContext);
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_CUDA
|
2013-09-21 01:29:00 +00:00
|
|
|
} else if (kernel == kCUDA) {
|
2014-09-05 22:07:46 +00:00
|
|
|
g_mesh = new OpenSubdiv::Osd::Mesh<OpenSubdiv::Osd::CudaGLVertexBuffer,
|
2015-05-09 00:31:26 +00:00
|
|
|
OpenSubdiv::Osd::CudaStencilTables,
|
|
|
|
OpenSubdiv::Osd::CudaEvaluator,
|
|
|
|
OpenSubdiv::Osd::GLDrawContext>(
|
2014-09-05 22:07:46 +00:00
|
|
|
refiner,
|
2013-06-27 19:57:21 +00:00
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
|
2013-09-21 01:29:00 +00:00
|
|
|
} else if (kernel == kGLSL) {
|
2015-05-09 00:31:26 +00:00
|
|
|
static OpenSubdiv::Osd::EvaluatorCacheT<OpenSubdiv::Osd::GLXFBEvaluator> glXFBEvaluatorCache;
|
2014-09-05 22:07:46 +00:00
|
|
|
g_mesh = new OpenSubdiv::Osd::Mesh<OpenSubdiv::Osd::GLVertexBuffer,
|
2015-05-09 00:31:26 +00:00
|
|
|
OpenSubdiv::Osd::GLStencilTablesTBO,
|
|
|
|
OpenSubdiv::Osd::GLXFBEvaluator,
|
|
|
|
OpenSubdiv::Osd::GLDrawContext>(
|
|
|
|
refiner,
|
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits,
|
|
|
|
&glXFBEvaluatorCache);
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
|
2013-09-21 01:29:00 +00:00
|
|
|
} else if (kernel == kGLSLCompute) {
|
2015-05-09 00:31:26 +00:00
|
|
|
static OpenSubdiv::Osd::EvaluatorCacheT<OpenSubdiv::Osd::GLComputeEvaluator> glComputeEvaluatorCache;
|
2014-09-05 22:07:46 +00:00
|
|
|
g_mesh = new OpenSubdiv::Osd::Mesh<OpenSubdiv::Osd::GLVertexBuffer,
|
2015-05-09 00:31:26 +00:00
|
|
|
OpenSubdiv::Osd::GLStencilTablesSSBO,
|
|
|
|
OpenSubdiv::Osd::GLComputeEvaluator,
|
|
|
|
OpenSubdiv::Osd::GLDrawContext>(
|
2014-09-05 22:07:46 +00:00
|
|
|
refiner,
|
2013-06-27 19:57:21 +00:00
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
2015-05-09 00:31:26 +00:00
|
|
|
level, bits,
|
|
|
|
&glComputeEvaluatorCache);
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
printf("Unsupported kernel %s\n", getKernelName(kernel));
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (glGetError() != GL_NO_ERROR) {
|
|
|
|
printf("GLERROR\n");
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
updateGeom();
|
2013-01-29 23:54:18 +00:00
|
|
|
|
|
|
|
// ------ VAO
|
|
|
|
glBindVertexArray(g_vao);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_mesh->BindVertexBuffer());
|
|
|
|
|
|
|
|
if (g_adaptive) {
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
|
|
|
} else {
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(1);
|
2013-09-21 01:29:00 +00:00
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, 0);
|
|
|
|
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, (float*)12);
|
2013-01-29 23:54:18 +00:00
|
|
|
}
|
2013-06-01 00:11:16 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_mesh->GetDrawContext()->GetPatchIndexBuffer());
|
2013-01-29 23:54:18 +00:00
|
|
|
|
2013-11-08 18:47:11 +00:00
|
|
|
// ------ Cage VAO
|
|
|
|
glBindVertexArray(g_cageEdgeVAO);
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_mesh->BindVertexBuffer());
|
|
|
|
|
|
|
|
if (g_adaptive) {
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
|
|
|
} else {
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 6, 0);
|
|
|
|
}
|
|
|
|
if (not g_edgeIndexBuffer) glGenBuffers(1, &g_edgeIndexBuffer);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_edgeIndexBuffer);
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int)*edgeIndices.size(),
|
|
|
|
&edgeIndices[0], GL_STATIC_DRAW);
|
|
|
|
g_numCageEdges = (int)edgeIndices.size();
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
glBindVertexArray(0);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
createSky() {
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
const int U_DIV = 20;
|
|
|
|
const int V_DIV = 20;
|
|
|
|
|
|
|
|
std::vector<float> vbo;
|
|
|
|
std::vector<int> indices;
|
|
|
|
for (int u = 0; u <= U_DIV; ++u) {
|
|
|
|
for (int v = 0; v < V_DIV; ++v) {
|
|
|
|
float s = float(2*M_PI*float(u)/U_DIV);
|
|
|
|
float t = float(M_PI*float(v)/(V_DIV-1));
|
|
|
|
vbo.push_back(-sin(t)*sin(s));
|
|
|
|
vbo.push_back(cos(t));
|
|
|
|
vbo.push_back(-sin(t)*cos(s));
|
|
|
|
vbo.push_back(u/float(U_DIV));
|
|
|
|
vbo.push_back(v/float(V_DIV));
|
|
|
|
|
|
|
|
if (v > 0 && u > 0) {
|
|
|
|
indices.push_back((u-1)*V_DIV+v-1);
|
|
|
|
indices.push_back(u*V_DIV+v-1);
|
|
|
|
indices.push_back((u-1)*V_DIV+v);
|
|
|
|
indices.push_back((u-1)*V_DIV+v);
|
|
|
|
indices.push_back(u*V_DIV+v-1);
|
|
|
|
indices.push_back(u*V_DIV+v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
glGenBuffers(1, &g_sky.vertexBuffer);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_sky.vertexBuffer);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*vbo.size(), &vbo[0], GL_STATIC_DRAW);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
|
|
|
glGenBuffers(1, &g_sky.elementBuffer);
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_sky.elementBuffer);
|
|
|
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(int)*indices.size(), &indices[0], GL_STATIC_DRAW);
|
|
|
|
|
|
|
|
g_sky.numIndices = (int)indices.size();
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
g_sky.BuildProgram(g_skyShaderSource);
|
|
|
|
|
|
|
|
GLint environmentMap = glGetUniformLocation(g_sky.GetProgram(), "environmentMap");
|
|
|
|
glUseProgram(g_sky.GetProgram());
|
2013-01-29 23:54:18 +00:00
|
|
|
if (g_specularEnvironmentMap)
|
2015-05-14 00:35:46 +00:00
|
|
|
glUniform1i(environmentMap, 6);
|
2013-01-29 23:54:18 +00:00
|
|
|
else
|
2015-05-14 00:35:46 +00:00
|
|
|
glUniform1i(environmentMap, 5);
|
2013-03-16 01:03:22 +00:00
|
|
|
glUseProgram(0);
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
g_sky.mvpMatrix = glGetUniformLocation(g_sky.GetProgram(), "ModelViewProjectionMatrix");
|
2013-03-16 01:03:22 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-11-08 18:47:11 +00:00
|
|
|
static void
|
2015-05-14 00:35:46 +00:00
|
|
|
updateConstantUniformBlock() {
|
|
|
|
struct Constant {
|
|
|
|
float ModelViewMatrix[16];
|
|
|
|
float ProjectionMatrix[16];
|
|
|
|
float ModelViewProjectionMatrix[16];
|
|
|
|
float ModelViewInverseMatrix[16];
|
2012-12-11 01:15:13 +00:00
|
|
|
struct Light {
|
|
|
|
float position[4];
|
|
|
|
float ambient[4];
|
|
|
|
float diffuse[4];
|
|
|
|
float specular[4];
|
|
|
|
} lightSource[2];
|
2015-05-14 00:35:46 +00:00
|
|
|
float TessLevel;
|
|
|
|
float displacementScale;
|
|
|
|
float mipmapBias;
|
|
|
|
} constantData;
|
|
|
|
|
|
|
|
// transforms
|
|
|
|
double aspect = g_width/(double)g_height;
|
|
|
|
identity(constantData.ModelViewMatrix);
|
|
|
|
translate(constantData.ModelViewMatrix, -g_pan[0], -g_pan[1], -g_dolly);
|
|
|
|
rotate(constantData.ModelViewMatrix, g_rotate[1], 1, 0, 0);
|
|
|
|
rotate(constantData.ModelViewMatrix, g_rotate[0], 0, 1, 0);
|
|
|
|
if (g_yup)
|
|
|
|
rotate(constantData.ModelViewMatrix, -90, 1, 0, 0);
|
|
|
|
translate(constantData.ModelViewMatrix, -g_center[0], -g_center[1], -g_center[2]);
|
|
|
|
perspective(constantData.ProjectionMatrix, 45.0f, (float)aspect, g_size*0.001f,
|
|
|
|
g_size+g_dolly);
|
|
|
|
multMatrix(constantData.ModelViewProjectionMatrix,
|
|
|
|
constantData.ModelViewMatrix,
|
|
|
|
constantData.ProjectionMatrix);
|
|
|
|
inverseMatrix(constantData.ModelViewInverseMatrix,
|
|
|
|
constantData.ModelViewMatrix);
|
|
|
|
|
|
|
|
// lighs
|
|
|
|
Constant::Light light0 = { { 0.6f, 1.0f, 0.6f, 0.0f },
|
|
|
|
{ 0.1f, 0.1f, 0.1f, 1.0f },
|
|
|
|
{ 1.7f, 1.3f, 1.1f, 1.0f },
|
|
|
|
{ 1.0f, 1.0f, 1.0f, 1.0f } };
|
|
|
|
Constant::Light light1 = { { -0.8f, 0.6f, -0.7f, 0.0f },
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
|
|
|
{ 0.8f, 0.8f, 1.5f, 1.0f },
|
|
|
|
{ 0.4f, 0.4f, 0.4f, 1.0f } };
|
|
|
|
constantData.lightSource[0] = light0;
|
|
|
|
constantData.lightSource[1] = light1;
|
|
|
|
|
|
|
|
// other
|
|
|
|
constantData.TessLevel = static_cast<float>(1 << g_tessLevel);
|
|
|
|
constantData.displacementScale = g_displacementScale;
|
|
|
|
constantData.mipmapBias = g_mipmapBias;
|
|
|
|
|
|
|
|
// update GPU buffer
|
|
|
|
if (g_constantUB == 0) {
|
|
|
|
glGenBuffers(1, &g_constantUB);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_constantUB);
|
2012-12-11 01:15:13 +00:00
|
|
|
glBufferData(GL_UNIFORM_BUFFER,
|
2015-05-14 00:35:46 +00:00
|
|
|
sizeof(constantData), NULL, GL_STATIC_DRAW);
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
2015-05-14 00:35:46 +00:00
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_constantUB);
|
2012-12-11 01:15:13 +00:00
|
|
|
glBufferSubData(GL_UNIFORM_BUFFER,
|
2015-05-14 00:35:46 +00:00
|
|
|
0, sizeof(constantData), &constantData);
|
2012-12-11 01:15:13 +00:00
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
glBindBufferBase(GL_UNIFORM_BUFFER, g_constantBinding, g_constantUB);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
}
|
2013-11-08 18:47:11 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
static void
|
|
|
|
bindTextures() {
|
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
|
|
|
if (g_mesh->GetDrawContext()->GetVertexTextureBuffer()) {
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER,
|
|
|
|
g_mesh->GetDrawContext()->GetVertexTextureBuffer());
|
|
|
|
}
|
|
|
|
if (g_mesh->GetDrawContext()->GetVertexValenceTextureBuffer()) {
|
|
|
|
glActiveTexture(GL_TEXTURE1);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER,
|
|
|
|
g_mesh->GetDrawContext()->GetVertexValenceTextureBuffer());
|
|
|
|
}
|
|
|
|
if (g_mesh->GetDrawContext()->GetQuadOffsetsTextureBuffer()) {
|
|
|
|
glActiveTexture(GL_TEXTURE2);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER,
|
|
|
|
g_mesh->GetDrawContext()->GetQuadOffsetsTextureBuffer());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (g_mesh->GetDrawContext()->GetPatchParamTextureBuffer()) {
|
|
|
|
glActiveTexture(GL_TEXTURE3);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER,
|
|
|
|
g_mesh->GetDrawContext()->GetPatchParamTextureBuffer());
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// other textures
|
|
|
|
if (g_ibl) {
|
|
|
|
if (g_diffuseEnvironmentMap) {
|
|
|
|
glActiveTexture(GL_TEXTURE5);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_diffuseEnvironmentMap);
|
|
|
|
}
|
|
|
|
if (g_specularEnvironmentMap) {
|
|
|
|
glActiveTexture(GL_TEXTURE6);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_specularEnvironmentMap);
|
|
|
|
}
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// color ptex
|
2015-05-14 00:35:46 +00:00
|
|
|
glActiveTexture(GL_TEXTURE7);
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, g_osdPTexImage->GetTexelsTexture());
|
|
|
|
glActiveTexture(GL_TEXTURE8);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, g_osdPTexImage->GetLayoutTextureBuffer());
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// displacement ptex
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_displacement != DISPLACEMENT_NONE || g_normal) {
|
2015-05-14 00:35:46 +00:00
|
|
|
glActiveTexture(GL_TEXTURE9);
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, g_osdPTexDisplacement->GetTexelsTexture());
|
|
|
|
glActiveTexture(GL_TEXTURE10);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, g_osdPTexDisplacement->GetLayoutTextureBuffer());
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// occlusion ptex
|
|
|
|
if (g_occlusion) {
|
2015-05-14 00:35:46 +00:00
|
|
|
glActiveTexture(GL_TEXTURE11);
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, g_osdPTexOcclusion->GetTexelsTexture());
|
|
|
|
glActiveTexture(GL_TEXTURE12);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, g_osdPTexOcclusion->GetLayoutTextureBuffer());
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// specular ptex
|
|
|
|
if (g_specular) {
|
2015-05-14 00:35:46 +00:00
|
|
|
glActiveTexture(GL_TEXTURE13);
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, g_osdPTexSpecular->GetTexelsTexture());
|
|
|
|
glActiveTexture(GL_TEXTURE14);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, g_osdPTexSpecular->GetLayoutTextureBuffer());
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static GLenum
|
|
|
|
bindProgram(Effect effect,
|
|
|
|
OpenSubdiv::Osd::DrawContext::PatchArray const & patch) {
|
|
|
|
EffectDesc effectDesc(patch.GetDescriptor(), effect);
|
|
|
|
|
|
|
|
// only legacy gregory needs maxValence and numElements
|
|
|
|
typedef OpenSubdiv::Far::PatchDescriptor Descriptor;
|
|
|
|
if (patch.GetDescriptor().GetType() == Descriptor::GREGORY or
|
|
|
|
patch.GetDescriptor().GetType() == Descriptor::GREGORY_BOUNDARY) {
|
|
|
|
int maxValence = g_mesh->GetDrawContext()->GetMaxValence();
|
|
|
|
effectDesc.maxValence = maxValence;
|
|
|
|
effectDesc.numElements = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLDrawConfig *config = g_shaderCache.GetDrawConfig(effectDesc);
|
|
|
|
if (!config) return 0;
|
|
|
|
|
|
|
|
GLuint program = config->GetProgram();
|
|
|
|
|
|
|
|
glUseProgram(program);
|
|
|
|
|
|
|
|
// bind standalone uniforms
|
|
|
|
GLint uniformGregoryQuadOffsetBase =
|
|
|
|
glGetUniformLocation(program, "GregoryQuadOffsetBase");
|
|
|
|
GLint uniformPrimitiveIdBase =
|
|
|
|
glGetUniformLocation(program, "PrimitiveIdBase");
|
|
|
|
|
|
|
|
if (uniformGregoryQuadOffsetBase >= 0)
|
|
|
|
glUniform1i(uniformGregoryQuadOffsetBase, patch.GetQuadOffsetIndex());
|
|
|
|
if (uniformPrimitiveIdBase >= 0)
|
|
|
|
glUniform1i(uniformPrimitiveIdBase, patch.GetPatchIndex());
|
|
|
|
|
|
|
|
GLenum primType;
|
|
|
|
switch(effectDesc.desc.GetType()) {
|
|
|
|
case OpenSubdiv::Far::PatchDescriptor::QUADS:
|
|
|
|
primType = GL_LINES_ADJACENCY;
|
|
|
|
break;
|
|
|
|
case OpenSubdiv::Far::PatchDescriptor::TRIANGLES:
|
|
|
|
primType = GL_TRIANGLES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
|
|
|
primType = GL_PATCHES;
|
|
|
|
glPatchParameteri(GL_PATCH_VERTICES, effectDesc.desc.GetNumControlVertices());
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
2015-05-14 00:35:46 +00:00
|
|
|
primType = GL_POINTS;
|
2013-01-29 23:54:18 +00:00
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
return primType;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
drawModel() {
|
2013-01-29 23:54:18 +00:00
|
|
|
g_mesh->BindVertexBuffer();
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// bind patch related textures and PtexTexture
|
|
|
|
bindTextures();
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
glBindVertexArray(g_vao);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
// patch drawing
|
2015-05-14 00:35:46 +00:00
|
|
|
OpenSubdiv::Osd::DrawContext::PatchArrayVector const & patches =
|
|
|
|
g_mesh->GetDrawContext()->GetPatchArrays();
|
2013-09-21 01:29:00 +00:00
|
|
|
for (int i = 0; i < (int)patches.size(); ++i) {
|
2014-09-05 22:07:46 +00:00
|
|
|
OpenSubdiv::Osd::DrawContext::PatchArray const & patch = patches[i];
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
Effect effect;
|
|
|
|
effect.value = 0;
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
effect.color = g_color;
|
|
|
|
effect.displacement = g_displacement;
|
2013-09-21 01:29:00 +00:00
|
|
|
effect.occlusion = g_occlusion;
|
2012-12-11 01:15:13 +00:00
|
|
|
effect.normal = g_normal;
|
|
|
|
effect.specular = g_specular;
|
|
|
|
effect.patchCull = g_patchCull;
|
|
|
|
effect.screenSpaceTess = g_screenSpaceTess;
|
2013-06-27 20:34:25 +00:00
|
|
|
effect.fractionalSpacing = g_fractionalSpacing;
|
2012-12-11 01:15:13 +00:00
|
|
|
effect.ibl = g_ibl;
|
|
|
|
effect.wire = g_wire;
|
2013-10-16 00:47:58 +00:00
|
|
|
effect.seamless = g_seamless;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
GLenum primType = bindProgram(effect, patch);
|
2013-03-08 01:50:15 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glDrawElements(primType,
|
2013-05-09 20:48:00 +00:00
|
|
|
patch.GetNumIndices(), GL_UNSIGNED_INT,
|
|
|
|
(void *)(patch.GetVertIndex() * sizeof(unsigned int)));
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2015-05-14 00:35:46 +00:00
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
glBindVertexArray(0);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
drawSky() {
|
2015-05-14 00:35:46 +00:00
|
|
|
glUseProgram(g_sky.GetProgram());
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_FALSE);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
float modelView[16], projection[16], mvp[16];
|
2013-01-29 23:54:18 +00:00
|
|
|
double aspect = g_width/(double)g_height;
|
|
|
|
|
|
|
|
identity(modelView);
|
|
|
|
rotate(modelView, g_rotate[1], 1, 0, 0);
|
|
|
|
rotate(modelView, g_rotate[0], 0, 1, 0);
|
|
|
|
perspective(projection, 45.0f, (float)aspect, g_size*0.001f, g_size+g_dolly);
|
2012-12-11 01:15:13 +00:00
|
|
|
multMatrix(mvp, modelView, projection);
|
2013-01-29 23:54:18 +00:00
|
|
|
glUniformMatrix4fv(g_sky.mvpMatrix, 1, GL_FALSE, mvp);
|
|
|
|
|
|
|
|
glBindVertexArray(g_skyVAO);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glEnableVertexAttribArray(1);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_sky.vertexBuffer);
|
2013-09-21 01:29:00 +00:00
|
|
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, 0);
|
|
|
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5,
|
|
|
|
(void*)(sizeof(GLfloat)*3));
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_sky.elementBuffer);
|
|
|
|
glDrawElements(GL_TRIANGLES, g_sky.numIndices, GL_UNSIGNED_INT, 0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glDisableVertexAttribArray(0);
|
|
|
|
glDisableVertexAttribArray(1);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
glBindVertexArray(0);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthMask(GL_TRUE);
|
2013-11-08 18:47:11 +00:00
|
|
|
|
|
|
|
checkGLErrors("draw model");
|
|
|
|
}
|
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2013-11-08 18:47:11 +00:00
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
drawCageEdges() {
|
|
|
|
|
2013-11-08 18:47:11 +00:00
|
|
|
g_mesh->BindVertexBuffer();
|
|
|
|
|
|
|
|
glBindVertexArray(g_cageEdgeVAO);
|
|
|
|
|
|
|
|
Effect effect;
|
|
|
|
effect.value = 0;
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
EffectDesc effectDesc(
|
|
|
|
OpenSubdiv::Far::PatchDescriptor(
|
|
|
|
OpenSubdiv::Far::PatchDescriptor::LINES), effect);
|
2014-11-25 20:41:19 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
GLDrawConfig *config = g_shaderCache.GetDrawConfig(effectDesc);
|
|
|
|
if (!config) return;
|
2013-11-08 18:47:11 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
glUseProgram(config->GetProgram());
|
2013-11-08 18:47:11 +00:00
|
|
|
glDrawElements(GL_LINES, g_numCageEdges, GL_UNSIGNED_INT, 0);
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glUseProgram(0);
|
|
|
|
|
|
|
|
checkGLErrors("draw cage edges");
|
2013-09-21 01:29:00 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
display() {
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
g_hud.GetFrameBuffer()->Bind();
|
2013-03-16 01:03:22 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
Stopwatch s;
|
|
|
|
s.Start();
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glViewport(0, 0, g_width, g_height);
|
2013-01-29 23:54:18 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (g_ibl) {
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
drawSky();
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
// update transform and light
|
|
|
|
updateConstantUniformBlock();
|
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
if (g_wire == DISPLAY_WIRE) {
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
}
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
// primitive counting
|
2014-05-15 17:26:23 +00:00
|
|
|
glBeginQuery(GL_PRIMITIVES_GENERATED, g_queries[0]);
|
|
|
|
#if defined(GL_VERSION_3_3)
|
|
|
|
glBeginQuery(GL_TIME_ELAPSED, g_queries[1]);
|
|
|
|
#endif
|
2013-01-29 23:54:18 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
drawModel();
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-11-08 18:47:11 +00:00
|
|
|
glEndQuery(GL_PRIMITIVES_GENERATED);
|
2014-05-15 17:26:23 +00:00
|
|
|
#if defined(GL_VERSION_3_3)
|
|
|
|
glEndQuery(GL_TIME_ELAPSED);
|
|
|
|
#endif
|
2013-11-08 18:47:11 +00:00
|
|
|
|
|
|
|
if (g_drawCageEdges)
|
|
|
|
drawCageEdges();
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
if (g_wire == DISPLAY_WIRE) {
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
}
|
2013-03-18 18:56:09 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glUseProgram(0);
|
|
|
|
|
|
|
|
s.Stop();
|
|
|
|
float drawCpuTime = float(s.GetElapsed() * 1000.0f);
|
|
|
|
|
|
|
|
GLuint numPrimsGenerated = 0;
|
2014-05-15 17:26:23 +00:00
|
|
|
GLuint timeElapsed = 0;
|
|
|
|
glGetQueryObjectuiv(g_queries[0], GL_QUERY_RESULT, &numPrimsGenerated);
|
|
|
|
#if defined(GL_VERSION_3_3)
|
|
|
|
glGetQueryObjectuiv(g_queries[1], GL_QUERY_RESULT, &timeElapsed);
|
|
|
|
#endif
|
|
|
|
float drawGpuTime = timeElapsed / 1000.0f / 1000.0f;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-18 22:06:48 +00:00
|
|
|
g_fpsTimer.Stop();
|
|
|
|
float elapsed = (float)g_fpsTimer.GetElapsed();
|
|
|
|
if (not g_freeze)
|
2013-03-16 01:03:22 +00:00
|
|
|
g_animTime += elapsed;
|
2013-07-18 22:06:48 +00:00
|
|
|
g_fpsTimer.Start();
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
g_hud.GetFrameBuffer()->ApplyImageShader();
|
|
|
|
|
2013-07-18 22:06:48 +00:00
|
|
|
if (g_hud.IsVisible()) {
|
2013-03-16 01:03:22 +00:00
|
|
|
double fps = 1.0/elapsed;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
// Avereage fps over a defined number of time samples for
|
|
|
|
// easier reading in the HUD
|
|
|
|
g_fpsTimeSamples[g_currentFpsTimeSample++] = float(fps);
|
|
|
|
if (g_currentFpsTimeSample >= NUM_FPS_TIME_SAMPLES)
|
|
|
|
g_currentFpsTimeSample = 0;
|
|
|
|
double averageFps = 0;
|
2013-09-21 01:29:00 +00:00
|
|
|
for (int i = 0; i < NUM_FPS_TIME_SAMPLES; ++i) {
|
2012-12-11 01:15:13 +00:00
|
|
|
averageFps += g_fpsTimeSamples[i]/(float)NUM_FPS_TIME_SAMPLES;
|
|
|
|
}
|
|
|
|
|
2013-10-08 02:06:40 +00:00
|
|
|
g_hud.DrawString(10, -220, "Ptex memory use : %.1f mb", g_ptexMemoryUsage/1024.0/1024.0);
|
2012-12-11 01:15:13 +00:00
|
|
|
g_hud.DrawString(10, -180, "Tess level (+/-): %d", g_tessLevel);
|
2013-01-10 19:14:41 +00:00
|
|
|
if (numPrimsGenerated > 1000000) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.DrawString(10, -160, "Primitives : %3.1f million",
|
|
|
|
(float)numPrimsGenerated/1000000.0);
|
2013-01-10 19:14:41 +00:00
|
|
|
} else if (numPrimsGenerated > 1000) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.DrawString(10, -160, "Primitives : %3.1f thousand",
|
|
|
|
(float)numPrimsGenerated/1000.0);
|
2013-01-10 19:14:41 +00:00
|
|
|
} else {
|
|
|
|
g_hud.DrawString(10, -160, "Primitives : %d", numPrimsGenerated);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
g_hud.DrawString(10, -140, "Vertices : %d", g_mesh->GetNumVertices());
|
|
|
|
g_hud.DrawString(10, -120, "Scheme : %s", g_scheme == 0 ? "CATMARK" : "LOOP");
|
|
|
|
g_hud.DrawString(10, -100, "GPU Kernel : %.3f ms", g_gpuTime);
|
|
|
|
g_hud.DrawString(10, -80, "CPU Kernel : %.3f ms", g_cpuTime);
|
|
|
|
g_hud.DrawString(10, -60, "GPU Draw : %.3f ms", drawGpuTime);
|
|
|
|
g_hud.DrawString(10, -40, "CPU Draw : %.3f ms", drawCpuTime);
|
|
|
|
g_hud.DrawString(10, -20, "FPS : %3.1f", averageFps);
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2013-01-31 23:34:35 +00:00
|
|
|
g_hud.Flush();
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glFinish();
|
|
|
|
|
2013-01-31 23:34:35 +00:00
|
|
|
checkGLErrors("draw end");
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-01-29 23:54:18 +00:00
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
mouse(GLFWwindow *, int button, int state, int /* mods */) {
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (state == GLFW_RELEASE)
|
|
|
|
g_hud.MouseRelease();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
if (button == 0 && state == GLFW_PRESS && g_hud.MouseClick(g_prev_x, g_prev_y))
|
|
|
|
return;
|
|
|
|
g_mbutton[button] = (state == GLFW_PRESS);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-09-21 01:29:00 +00:00
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
motion(GLFWwindow *, double dx, double dy) {
|
2013-09-21 01:29:00 +00:00
|
|
|
int x = (int)dx, y = (int)dy;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_hud.MouseCapture()) {
|
|
|
|
// check gui
|
|
|
|
g_hud.MouseMotion(x, y);
|
|
|
|
} else if (g_mbutton[0] && !g_mbutton[1] && !g_mbutton[2]) {
|
2012-08-04 02:51:27 +00:00
|
|
|
// orbit
|
|
|
|
g_rotate[0] += x - g_prev_x;
|
|
|
|
g_rotate[1] += y - g_prev_y;
|
2013-01-29 23:54:18 +00:00
|
|
|
} else if (!g_mbutton[0] && !g_mbutton[1] && g_mbutton[2]) {
|
2012-08-04 02:51:27 +00:00
|
|
|
// pan
|
|
|
|
g_pan[0] -= g_dolly*(x - g_prev_x)/g_width;
|
|
|
|
g_pan[1] += g_dolly*(y - g_prev_y)/g_height;
|
2013-01-29 23:54:18 +00:00
|
|
|
} else if ((g_mbutton[0] && !g_mbutton[1] && g_mbutton[2]) or
|
|
|
|
(!g_mbutton[0] && g_mbutton[1] && !g_mbutton[2])) {
|
2012-08-04 02:51:27 +00:00
|
|
|
// dolly
|
|
|
|
g_dolly -= g_dolly*0.01f*(x - g_prev_x);
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_dolly <= 0.01) g_dolly = 0.01f;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
g_prev_x = x;
|
|
|
|
g_prev_y = y;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2014-09-05 22:07:46 +00:00
|
|
|
void uninitGL() {
|
2012-12-11 01:15:13 +00:00
|
|
|
if (g_osdPTexImage) delete g_osdPTexImage;
|
|
|
|
if (g_osdPTexDisplacement) delete g_osdPTexDisplacement;
|
|
|
|
if (g_osdPTexOcclusion) delete g_osdPTexOcclusion;
|
|
|
|
if (g_osdPTexSpecular) delete g_osdPTexSpecular;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-05-15 17:26:23 +00:00
|
|
|
glDeleteQueries(2, g_queries);
|
2013-01-29 23:54:18 +00:00
|
|
|
glDeleteVertexArrays(1, &g_vao);
|
2013-11-08 18:47:11 +00:00
|
|
|
glDeleteVertexArrays(1, &g_cageEdgeVAO);
|
2013-01-29 23:54:18 +00:00
|
|
|
glDeleteVertexArrays(1, &g_skyVAO);
|
2012-08-22 20:57:36 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_mesh)
|
2012-12-11 01:15:13 +00:00
|
|
|
delete g_mesh;
|
2012-08-22 20:57:36 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_diffuseEnvironmentMap)
|
|
|
|
glDeleteTextures(1, &g_diffuseEnvironmentMap);
|
|
|
|
if (g_specularEnvironmentMap)
|
|
|
|
glDeleteTextures(1, &g_specularEnvironmentMap);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
if (g_sky.vertexBuffer) glDeleteBuffers(1, &g_sky.vertexBuffer);
|
|
|
|
if (g_sky.elementBuffer) glDeleteBuffers(1, &g_sky.elementBuffer);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2012-12-11 01:15:13 +00:00
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackWireframe(int b) {
|
2012-12-11 01:15:13 +00:00
|
|
|
g_wire = b;
|
|
|
|
}
|
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackKernel(int k) {
|
2012-08-04 02:51:27 +00:00
|
|
|
g_kernel = k;
|
2013-09-21 01:29:00 +00:00
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2015-04-28 22:46:37 +00:00
|
|
|
if (g_kernel == kCL and (not g_clDeviceContext.IsInitialized())) {
|
2013-09-21 01:29:00 +00:00
|
|
|
// Initialize OpenCL
|
2015-04-28 22:46:37 +00:00
|
|
|
if (g_clDeviceContext.Initialize() == false) {
|
2013-09-21 01:29:00 +00:00
|
|
|
printf("Error in initializing OpenCL\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2015-04-28 22:46:37 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_CUDA
|
|
|
|
if (g_kernel == kCUDA and (not g_cudaDeviceContext.IsInitialized())) {
|
|
|
|
if (g_cudaDeviceContext.Initialize() == false) {
|
|
|
|
printf("Error in initializing Cuda\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
#endif
|
2013-10-05 01:23:20 +00:00
|
|
|
createOsdMesh(g_level, g_kernel);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackScheme(int s) {
|
2012-12-11 01:15:13 +00:00
|
|
|
g_scheme = s;
|
|
|
|
createOsdMesh(g_level, g_kernel);
|
|
|
|
}
|
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackLevel(int l) {
|
2012-08-04 02:51:27 +00:00
|
|
|
g_level = l;
|
|
|
|
createOsdMesh(g_level, g_kernel);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackColor(int c) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_color = c;
|
|
|
|
}
|
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackDisplacement(int d) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_displacement = d;
|
|
|
|
}
|
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackNormal(int n) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_normal = n;
|
|
|
|
}
|
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackCheckBox(bool checked, int button) {
|
2012-12-11 01:15:13 +00:00
|
|
|
bool rebuild = false;
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
switch (button) {
|
2012-12-11 01:15:13 +00:00
|
|
|
case HUD_CB_ADAPTIVE:
|
2015-05-19 01:04:38 +00:00
|
|
|
if (GLUtils::SupportsAdaptiveTessellation()) {
|
2013-02-05 23:25:46 +00:00
|
|
|
g_adaptive = checked;
|
|
|
|
rebuild = true;
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
break;
|
|
|
|
case HUD_CB_DISPLAY_OCCLUSION:
|
|
|
|
g_occlusion = checked;
|
|
|
|
break;
|
|
|
|
case HUD_CB_DISPLAY_SPECULAR:
|
|
|
|
g_specular = checked;
|
|
|
|
break;
|
2013-11-08 18:47:11 +00:00
|
|
|
case HUD_CB_CAGE_EDGES:
|
|
|
|
g_drawCageEdges = checked;
|
|
|
|
break;
|
2012-12-11 01:15:13 +00:00
|
|
|
case HUD_CB_ANIMATE_VERTICES:
|
|
|
|
g_moveScale = checked ? 1.0f : 0.0f;
|
2013-03-16 01:03:22 +00:00
|
|
|
g_animTime = 0;
|
2012-12-11 01:15:13 +00:00
|
|
|
break;
|
|
|
|
case HUD_CB_VIEW_LOD:
|
|
|
|
g_screenSpaceTess = checked;
|
|
|
|
break;
|
2013-06-27 20:34:25 +00:00
|
|
|
case HUD_CB_FRACTIONAL_SPACING:
|
|
|
|
g_fractionalSpacing = checked;
|
|
|
|
break;
|
2012-12-11 01:15:13 +00:00
|
|
|
case HUD_CB_PATCH_CULL:
|
|
|
|
g_patchCull = checked;
|
|
|
|
break;
|
|
|
|
case HUD_CB_IBL:
|
|
|
|
g_ibl = checked;
|
|
|
|
break;
|
2013-03-16 01:03:22 +00:00
|
|
|
case HUD_CB_BLOOM:
|
|
|
|
g_bloom = checked;
|
|
|
|
break;
|
2013-10-16 00:47:58 +00:00
|
|
|
case HUD_CB_SEAMLESS_MIPMAP:
|
|
|
|
g_seamless = checked;
|
|
|
|
break;
|
2013-07-18 22:06:48 +00:00
|
|
|
case HUD_CB_FREEZE:
|
|
|
|
g_freeze = checked;
|
|
|
|
break;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (rebuild)
|
|
|
|
createOsdMesh(g_level, g_kernel);
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
callbackSlider(float value, int data) {
|
2013-09-21 01:29:00 +00:00
|
|
|
switch (data) {
|
|
|
|
case 0:
|
|
|
|
g_mipmapBias = value;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
g_displacementScale = value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2012-08-04 02:51:27 +00:00
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
reloadShaderFile() {
|
2012-12-11 01:15:13 +00:00
|
|
|
if (not g_shaderFilename) return;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
std::ifstream ifs(g_shaderFilename);
|
|
|
|
if (not ifs) return;
|
|
|
|
printf("Load shader %s\n", g_shaderFilename);
|
|
|
|
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << ifs.rdbuf();
|
|
|
|
ifs.close();
|
|
|
|
|
|
|
|
g_shaderSource = ss.str();
|
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
g_shaderCache.Reset();
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-09-21 01:29:00 +00:00
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
toggleFullScreen() {
|
2013-02-08 22:06:44 +00:00
|
|
|
// XXXX manuelk : to re-implement from glut
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
keyboard(GLFWwindow *, int key, int /* scancode */, int event, int /* mods */) {
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
if (event == GLFW_RELEASE) return;
|
|
|
|
if (g_hud.KeyDown(tolower(key))) return;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
switch (key) {
|
2013-01-29 23:54:18 +00:00
|
|
|
case 'Q': g_running = 0; break;
|
|
|
|
case 'E': g_drawNormals = (g_drawNormals+1)%2; break;
|
|
|
|
case 'F': fitFrame(); break;
|
|
|
|
case GLFW_KEY_TAB: toggleFullScreen(); break;
|
|
|
|
case 'R': reloadShaderFile(); createOsdMesh(g_level, g_kernel); break;
|
2012-12-11 01:15:13 +00:00
|
|
|
case '+':
|
|
|
|
case '=': g_tessLevel++; break;
|
|
|
|
case '-': g_tessLevel = std::max(1, g_tessLevel-1); break;
|
2013-06-20 18:53:33 +00:00
|
|
|
case GLFW_KEY_ESCAPE: g_hud.SetVisible(!g_hud.IsVisible()); break;
|
2015-05-14 00:35:46 +00:00
|
|
|
case 'X': g_hud.GetFrameBuffer()->Screenshot(); break;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
idle() {
|
2013-07-18 22:06:48 +00:00
|
|
|
if (not g_freeze)
|
|
|
|
g_frame++;
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
updateGeom();
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_repeatCount != 0 && g_frame >= g_repeatCount)
|
2013-01-29 23:54:18 +00:00
|
|
|
g_running = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2014-09-05 22:07:46 +00:00
|
|
|
initGL() {
|
2014-01-23 21:21:42 +00:00
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 0.0f);
|
2012-08-04 02:51:27 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glDepthFunc(GL_LEQUAL);
|
2012-12-11 01:15:13 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-05-15 17:26:23 +00:00
|
|
|
glGenQueries(2, g_queries);
|
2013-01-29 23:54:18 +00:00
|
|
|
glGenVertexArrays(1, &g_vao);
|
2013-11-08 18:47:11 +00:00
|
|
|
glGenVertexArrays(1, &g_cageEdgeVAO);
|
2013-01-29 23:54:18 +00:00
|
|
|
glGenVertexArrays(1, &g_skyVAO);
|
2013-03-16 01:03:22 +00:00
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2014-09-05 22:07:46 +00:00
|
|
|
void usage(const char *program) {
|
2012-12-11 01:15:13 +00:00
|
|
|
printf("Usage: %s [options] <color.ptx> [<displacement.ptx>] [occlusion.ptx>] "
|
|
|
|
"[specular.ptx] [pose.obj]...\n", program);
|
|
|
|
printf("Options: -l level : subdivision level\n");
|
|
|
|
printf(" -c count : frame count until exit (for profiler)\n");
|
|
|
|
printf(" -d <diffseEnvMap.hdr> : diffuse environment map for IBL\n");
|
|
|
|
printf(" -e <specularEnvMap.hdr> : specular environment map for IBL\n");
|
|
|
|
printf(" -s <shaderfile.glsl> : custom shader file\n");
|
2013-03-16 01:03:22 +00:00
|
|
|
printf(" -y : Y-up model\n");
|
2013-09-21 01:29:00 +00:00
|
|
|
printf(" -m level : max mimmap level (default=10)\n");
|
2013-10-08 02:06:40 +00:00
|
|
|
printf(" -x <ptex limit MB> : ptex target memory size\n");
|
2013-03-16 01:03:22 +00:00
|
|
|
printf(" --disp <scale> : Displacment scale\n");
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-01-29 23:54:18 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
2014-12-04 01:19:07 +00:00
|
|
|
callbackError(OpenSubdiv::Far::ErrorType err, const char *message) {
|
|
|
|
printf("Error: %d\n", err);
|
2013-01-29 23:54:18 +00:00
|
|
|
printf("%s", message);
|
|
|
|
}
|
2013-01-31 23:34:35 +00:00
|
|
|
|
2014-12-20 22:44:50 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
callbackErrorGLFW(int error, const char* description) {
|
|
|
|
fprintf(stderr, "GLFW Error (%d) : %s\n", error, description);
|
|
|
|
}
|
2013-01-31 23:34:35 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
2014-09-05 22:07:46 +00:00
|
|
|
setGLCoreProfile() {
|
|
|
|
|
2013-01-31 23:34:35 +00:00
|
|
|
#define glfwOpenWindowHint glfwWindowHint
|
|
|
|
#define GLFW_OPENGL_VERSION_MAJOR GLFW_CONTEXT_VERSION_MAJOR
|
|
|
|
#define GLFW_OPENGL_VERSION_MINOR GLFW_CONTEXT_VERSION_MINOR
|
|
|
|
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
#if not defined(__APPLE__)
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
|
2014-02-22 03:25:00 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
|
|
|
|
#else
|
2013-01-31 23:34:35 +00:00
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
2014-02-22 03:25:00 +00:00
|
|
|
#endif
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-01-31 23:34:35 +00:00
|
|
|
#else
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
|
|
|
#endif
|
2013-09-12 17:14:48 +00:00
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
2013-01-31 23:34:35 +00:00
|
|
|
}
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2014-09-05 22:07:46 +00:00
|
|
|
int main(int argc, char ** argv) {
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
std::vector<std::string> animobjs;
|
|
|
|
const char *diffuseEnvironmentMap = NULL, *specularEnvironmentMap = NULL;
|
|
|
|
const char *colorFilename = NULL, *displacementFilename = NULL,
|
|
|
|
*occlusionFilename = NULL, *specularFilename = NULL;
|
2013-10-08 02:06:40 +00:00
|
|
|
int memLimit = 0, colorMem = 0, displacementMem = 0,
|
|
|
|
occlusionMem = 0, specularMem = 0;
|
2013-01-29 23:54:18 +00:00
|
|
|
bool fullscreen = false;
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
2013-09-21 01:29:00 +00:00
|
|
|
if (strstr(argv[i], ".obj"))
|
2012-12-11 01:15:13 +00:00
|
|
|
animobjs.push_back(argv[i]);
|
2013-09-21 01:29:00 +00:00
|
|
|
else if (!strcmp(argv[i], "-l"))
|
2012-12-11 01:15:13 +00:00
|
|
|
g_level = atoi(argv[++i]);
|
|
|
|
else if (!strcmp(argv[i], "-c"))
|
|
|
|
g_repeatCount = atoi(argv[++i]);
|
|
|
|
else if (!strcmp(argv[i], "-d"))
|
|
|
|
diffuseEnvironmentMap = argv[++i];
|
|
|
|
else if (!strcmp(argv[i], "-e"))
|
|
|
|
specularEnvironmentMap = argv[++i];
|
|
|
|
else if (!strcmp(argv[i], "-s"))
|
|
|
|
g_shaderFilename = argv[++i];
|
2013-01-29 23:54:18 +00:00
|
|
|
else if (!strcmp(argv[i], "-f"))
|
|
|
|
fullscreen = true;
|
2013-03-16 01:03:22 +00:00
|
|
|
else if (!strcmp(argv[i], "-y"))
|
|
|
|
g_yup = true;
|
2013-09-21 01:29:00 +00:00
|
|
|
else if (!strcmp(argv[i], "-m"))
|
|
|
|
g_maxMipmapLevels = atoi(argv[++i]);
|
2013-10-08 02:06:40 +00:00
|
|
|
else if (!strcmp(argv[i], "-x"))
|
|
|
|
memLimit = atoi(argv[++i]);
|
2013-03-16 01:03:22 +00:00
|
|
|
else if (!strcmp(argv[i], "--disp"))
|
2013-03-18 18:56:09 +00:00
|
|
|
g_displacementScale = (float)atof(argv[++i]);
|
2013-10-08 02:06:40 +00:00
|
|
|
else if (colorFilename == NULL) {
|
2012-12-11 01:15:13 +00:00
|
|
|
colorFilename = argv[i];
|
2013-10-08 02:06:40 +00:00
|
|
|
colorMem = memLimit;
|
|
|
|
} else if (displacementFilename == NULL) {
|
2012-12-11 01:15:13 +00:00
|
|
|
displacementFilename = argv[i];
|
2013-10-08 02:06:40 +00:00
|
|
|
displacementMem = memLimit;
|
2013-09-21 01:29:00 +00:00
|
|
|
g_displacement = DISPLACEMENT_BILINEAR;
|
|
|
|
g_normal = NORMAL_BIQUADRATIC;
|
2012-12-11 01:15:13 +00:00
|
|
|
} else if (occlusionFilename == NULL) {
|
|
|
|
occlusionFilename = argv[i];
|
2013-10-08 02:06:40 +00:00
|
|
|
occlusionMem = memLimit;
|
2012-12-11 01:15:13 +00:00
|
|
|
g_occlusion = 1;
|
|
|
|
} else if (specularFilename == NULL) {
|
|
|
|
specularFilename = argv[i];
|
2013-10-08 02:06:40 +00:00
|
|
|
specularMem = memLimit;
|
2012-12-11 01:15:13 +00:00
|
|
|
g_specular = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-04 01:19:07 +00:00
|
|
|
OpenSubdiv::Far::SetErrorCallback(callbackError);
|
2013-01-29 23:54:18 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
g_shaderSource = g_defaultShaderSource;
|
|
|
|
reloadShaderFile();
|
|
|
|
|
|
|
|
g_ptexColorFilename = colorFilename;
|
|
|
|
if (g_ptexColorFilename == NULL) {
|
|
|
|
usage(argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-12-20 22:44:50 +00:00
|
|
|
glfwSetErrorCallback(callbackErrorGLFW);
|
2013-01-31 23:34:35 +00:00
|
|
|
if (not glfwInit()) {
|
|
|
|
printf("Failed to initialize GLFW\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
static const char windowTitle[] = "OpenSubdiv glPtexViewer" OPENSUBDIV_VERSION_STRING;
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
#define CORE_PROFILE
|
|
|
|
#ifdef CORE_PROFILE
|
2013-01-31 23:34:35 +00:00
|
|
|
setGLCoreProfile();
|
2013-01-29 23:54:18 +00:00
|
|
|
#endif
|
2013-01-31 23:34:35 +00:00
|
|
|
|
2013-02-06 02:01:30 +00:00
|
|
|
if (fullscreen) {
|
|
|
|
g_primary = glfwGetPrimaryMonitor();
|
|
|
|
|
|
|
|
// apparently glfwGetPrimaryMonitor fails under linux : if no primary,
|
2013-09-21 01:29:00 +00:00
|
|
|
// settle for the first one in the list
|
2013-02-06 02:01:30 +00:00
|
|
|
if (not g_primary) {
|
2013-09-21 01:29:00 +00:00
|
|
|
int count = 0;
|
2013-02-06 02:01:30 +00:00
|
|
|
GLFWmonitor ** monitors = glfwGetMonitors(&count);
|
|
|
|
|
|
|
|
if (count)
|
|
|
|
g_primary = monitors[0];
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2013-02-06 02:01:30 +00:00
|
|
|
if (g_primary) {
|
2013-06-20 18:53:33 +00:00
|
|
|
GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary);
|
|
|
|
g_width = vidmode->width;
|
|
|
|
g_height = vidmode->height;
|
2013-02-06 02:01:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle,
|
2013-02-06 02:01:30 +00:00
|
|
|
fullscreen and g_primary ? g_primary : NULL, NULL))) {
|
2013-01-31 23:34:35 +00:00
|
|
|
printf("Failed to open window.\n");
|
|
|
|
glfwTerminate();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
glfwMakeContextCurrent(g_window);
|
|
|
|
glfwSetKeyCallback(g_window, keyboard);
|
|
|
|
glfwSetCursorPosCallback(g_window, motion);
|
|
|
|
glfwSetMouseButtonCallback(g_window, mouse);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-06-26 07:52:57 +00:00
|
|
|
#if defined(OSD_USES_GLEW)
|
2013-01-29 23:54:18 +00:00
|
|
|
#ifdef CORE_PROFILE
|
|
|
|
// this is the only way to initialize glew correctly under core profile context.
|
|
|
|
glewExperimental = true;
|
|
|
|
#endif
|
|
|
|
if (GLenum r = glewInit() != GLEW_OK) {
|
2013-01-31 23:34:35 +00:00
|
|
|
printf("Failed to initialize glew. error = %d\n", r);
|
2013-01-29 23:54:18 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#ifdef CORE_PROFILE
|
|
|
|
// clear GL errors which was generated during glewInit()
|
|
|
|
glGetError();
|
|
|
|
#endif
|
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
initGL();
|
|
|
|
|
2014-02-22 03:25:00 +00:00
|
|
|
// accommodate high DPI displays (e.g. mac retina displays)
|
|
|
|
glfwGetFramebufferSize(g_window, &g_width, &g_height);
|
|
|
|
glfwSetFramebufferSizeCallback(g_window, reshape);
|
|
|
|
|
2013-03-19 21:31:44 +00:00
|
|
|
glfwSetWindowCloseCallback(g_window, windowClose);
|
2013-06-20 20:51:07 +00:00
|
|
|
// as of GLFW 3.0.1 this callback is not implicit
|
|
|
|
reshape();
|
2013-03-16 01:03:22 +00:00
|
|
|
|
2013-02-05 23:25:46 +00:00
|
|
|
// activate feature adaptive tessellation if OSD supports it
|
2015-05-19 01:04:38 +00:00
|
|
|
g_adaptive = GLUtils::SupportsAdaptiveTessellation();
|
2013-02-05 23:25:46 +00:00
|
|
|
|
2014-02-22 03:25:00 +00:00
|
|
|
int windowWidth = g_width, windowHeight = g_height;
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-02-22 03:25:00 +00:00
|
|
|
// window size might not match framebuffer size on a high DPI display
|
|
|
|
glfwGetWindowSize(g_window, &windowWidth, &windowHeight);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2014-10-24 18:15:19 +00:00
|
|
|
g_hud.Init(windowWidth, windowHeight, g_width, g_height);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
g_hud.SetFrameBuffer(new GLFrameBuffer);
|
|
|
|
|
2014-04-28 19:09:15 +00:00
|
|
|
if (occlusionFilename != NULL) {
|
|
|
|
g_hud.AddCheckBox("Ambient Occlusion (A)", g_occlusion,
|
2014-09-05 22:07:46 +00:00
|
|
|
-200, 570, callbackCheckBox, HUD_CB_DISPLAY_OCCLUSION, 'a');
|
2014-04-28 19:09:15 +00:00
|
|
|
}
|
|
|
|
if (specularFilename != NULL)
|
|
|
|
g_hud.AddCheckBox("Specular (S)", g_specular,
|
2014-09-05 22:07:46 +00:00
|
|
|
-200, 590, callbackCheckBox, HUD_CB_DISPLAY_SPECULAR, 's');
|
2014-04-28 19:09:15 +00:00
|
|
|
|
2014-09-05 22:07:46 +00:00
|
|
|
if (diffuseEnvironmentMap or specularEnvironmentMap) {
|
2014-04-28 19:09:15 +00:00
|
|
|
g_hud.AddCheckBox("IBL (I)", g_ibl,
|
2014-09-05 22:07:46 +00:00
|
|
|
-200, 610, callbackCheckBox, HUD_CB_IBL, 'i');
|
2014-04-28 19:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_hud.AddCheckBox("Cage Edges (H)", g_drawCageEdges != 0,
|
|
|
|
10, 10, callbackCheckBox, HUD_CB_CAGE_EDGES, 'h');
|
|
|
|
g_hud.AddCheckBox("Animate vertices (M)", g_moveScale != 0.0,
|
|
|
|
10, 30, callbackCheckBox, HUD_CB_ANIMATE_VERTICES, 'm');
|
|
|
|
g_hud.AddCheckBox("Screen space LOD (V)", g_screenSpaceTess,
|
|
|
|
10, 50, callbackCheckBox, HUD_CB_VIEW_LOD, 'v');
|
|
|
|
g_hud.AddCheckBox("Fractional spacing (T)", g_fractionalSpacing,
|
|
|
|
10, 70, callbackCheckBox, HUD_CB_FRACTIONAL_SPACING, 't');
|
|
|
|
g_hud.AddCheckBox("Frustum Patch Culling (B)", g_patchCull,
|
|
|
|
10, 90, callbackCheckBox, HUD_CB_PATCH_CULL, 'b');
|
|
|
|
g_hud.AddCheckBox("Bloom (Y)", g_bloom,
|
|
|
|
10, 110, callbackCheckBox, HUD_CB_BLOOM, 'y');
|
|
|
|
g_hud.AddCheckBox("Freeze (spc)", g_freeze,
|
|
|
|
10, 130, callbackCheckBox, HUD_CB_FREEZE, ' ');
|
|
|
|
|
|
|
|
g_hud.AddRadioButton(HUD_RB_SCHEME, "CATMARK", true, 10, 190, callbackScheme, 0);
|
|
|
|
g_hud.AddRadioButton(HUD_RB_SCHEME, "BILINEAR", false, 10, 210, callbackScheme, 1);
|
|
|
|
|
2015-05-19 01:04:38 +00:00
|
|
|
if (GLUtils::SupportsAdaptiveTessellation())
|
2014-04-28 19:09:15 +00:00
|
|
|
g_hud.AddCheckBox("Adaptive (`)", g_adaptive,
|
|
|
|
10, 300, callbackCheckBox, HUD_CB_ADAPTIVE, '`');
|
|
|
|
|
|
|
|
for (int i = 1; i < 8; ++i) {
|
|
|
|
char level[16];
|
|
|
|
sprintf(level, "Lv. %d", i);
|
|
|
|
g_hud.AddRadioButton(HUD_RB_LEVEL, level, i == g_level,
|
|
|
|
10, 320+i*20, callbackLevel, i, '0'+i);
|
|
|
|
}
|
|
|
|
|
2014-04-28 23:36:39 +00:00
|
|
|
int compute_pulldown = g_hud.AddPullDown("Compute (K)", 475, 10, 300, callbackKernel, 'k');
|
2014-04-28 06:05:18 +00:00
|
|
|
g_hud.AddPullDownButton(compute_pulldown, "CPU", kCPU);
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENMP
|
2014-04-28 06:05:18 +00:00
|
|
|
g_hud.AddPullDownButton(compute_pulldown, "OpenMP", kOPENMP);
|
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_TBB
|
|
|
|
g_hud.AddPullDownButton(compute_pulldown, "TBB", kTBB);
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_CUDA
|
2014-04-28 06:05:18 +00:00
|
|
|
g_hud.AddPullDownButton(compute_pulldown, "CUDA", kCUDA);
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2015-04-28 22:46:37 +00:00
|
|
|
if (CLDeviceContext::HAS_CL_VERSION_1_1()) {
|
2014-05-21 08:10:45 +00:00
|
|
|
g_hud.AddPullDownButton(compute_pulldown, "OpenCL", kCL);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
|
2014-04-28 06:05:18 +00:00
|
|
|
g_hud.AddPullDownButton(compute_pulldown, "GLSL TransformFeedback", kGLSL);
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
|
|
|
|
// Must also check at run time for OpenGL 4.3
|
|
|
|
if (GLEW_VERSION_4_3) {
|
2014-04-28 06:05:18 +00:00
|
|
|
g_hud.AddPullDownButton(compute_pulldown, "GLSL Compute", kGLSLCompute);
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2014-04-28 23:36:39 +00:00
|
|
|
int shading_pulldown = g_hud.AddPullDown("Shading (W)", 250, 10, 250, callbackWireframe, 'w');
|
|
|
|
g_hud.AddPullDownButton(shading_pulldown, "Wire", DISPLAY_WIRE, g_wire==DISPLAY_WIRE);
|
|
|
|
g_hud.AddPullDownButton(shading_pulldown, "Shaded", DISPLAY_SHADED, g_wire==DISPLAY_SHADED);
|
|
|
|
g_hud.AddPullDownButton(shading_pulldown, "Wire+Shaded", DISPLAY_WIRE_ON_SHADED, g_wire==DISPLAY_WIRE_ON_SHADED);
|
2013-09-21 01:29:00 +00:00
|
|
|
|
|
|
|
g_hud.AddLabel("Color (C)", -200, 10);
|
|
|
|
g_hud.AddRadioButton(HUD_RB_COLOR, "None", (g_color == COLOR_NONE),
|
|
|
|
-200, 30, callbackColor, COLOR_NONE, 'c');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_COLOR, "Ptex Nearest", (g_color == COLOR_PTEX_NEAREST),
|
|
|
|
-200, 50, callbackColor, COLOR_PTEX_NEAREST, 'c');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_COLOR, "Ptex HW bilinear", (g_color == COLOR_PTEX_HW_BILINEAR),
|
|
|
|
-200, 70, callbackColor, COLOR_PTEX_HW_BILINEAR, 'c');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_COLOR, "Ptex bilinear", (g_color == COLOR_PTEX_BILINEAR),
|
|
|
|
-200, 90, callbackColor, COLOR_PTEX_BILINEAR, 'c');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_COLOR, "Ptex biquadratic", (g_color == COLOR_PTEX_BIQUADRATIC),
|
|
|
|
-200, 110, callbackColor, COLOR_PTEX_BIQUADRATIC, 'c');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_COLOR, "Patch type", (g_color == COLOR_PATCHTYPE),
|
|
|
|
-200, 130, callbackColor, COLOR_PATCHTYPE, 'c');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_COLOR, "Patch coord", (g_color == COLOR_PATCHCOORD),
|
|
|
|
-200, 150, callbackColor, COLOR_PATCHCOORD, 'c');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_COLOR, "Normal", (g_color == COLOR_NORMAL),
|
|
|
|
-200, 170, callbackColor, COLOR_NORMAL, 'c');
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
if (displacementFilename != NULL) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddLabel("Displacement (D)", -200, 200);
|
|
|
|
g_hud.AddRadioButton(HUD_RB_DISPLACEMENT, "None",
|
|
|
|
(g_displacement == DISPLACEMENT_NONE),
|
|
|
|
-200, 220, callbackDisplacement, DISPLACEMENT_NONE, 'd');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_DISPLACEMENT, "HW bilinear",
|
|
|
|
(g_displacement == DISPLACEMENT_HW_BILINEAR),
|
|
|
|
-200, 240, callbackDisplacement, DISPLACEMENT_HW_BILINEAR, 'd');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_DISPLACEMENT, "Bilinear",
|
|
|
|
(g_displacement == DISPLACEMENT_BILINEAR),
|
|
|
|
-200, 260, callbackDisplacement, DISPLACEMENT_BILINEAR, 'd');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_DISPLACEMENT, "Biquadratic",
|
|
|
|
(g_displacement == DISPLACEMENT_BIQUADRATIC),
|
|
|
|
-200, 280, callbackDisplacement, DISPLACEMENT_BIQUADRATIC, 'd');
|
|
|
|
|
|
|
|
g_hud.AddLabel("Normal (N)", -200, 310);
|
2013-09-26 16:31:54 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_NORMAL, "Surface",
|
|
|
|
(g_normal == NORMAL_SURFACE),
|
|
|
|
-200, 330, callbackNormal, NORMAL_SURFACE, 'n');
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_NORMAL, "Facet",
|
|
|
|
(g_normal == NORMAL_FACET),
|
2013-09-26 16:31:54 +00:00
|
|
|
-200, 350, callbackNormal, NORMAL_FACET, 'n');
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_NORMAL, "HW Screen space",
|
|
|
|
(g_normal == NORMAL_HW_SCREENSPACE),
|
2013-09-26 16:31:54 +00:00
|
|
|
-200, 370, callbackNormal, NORMAL_HW_SCREENSPACE, 'n');
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_NORMAL, "Screen space",
|
|
|
|
(g_normal == NORMAL_SCREENSPACE),
|
2013-09-26 16:31:54 +00:00
|
|
|
-200, 390, callbackNormal, NORMAL_SCREENSPACE, 'n');
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_NORMAL, "Biquadratic",
|
|
|
|
(g_normal == NORMAL_BIQUADRATIC),
|
2013-09-26 16:31:54 +00:00
|
|
|
-200, 410, callbackNormal, NORMAL_BIQUADRATIC, 'n');
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_NORMAL, "Biquadratic WG",
|
|
|
|
(g_normal == NORMAL_BIQUADRATIC_WG),
|
2013-09-26 16:31:54 +00:00
|
|
|
-200, 430, callbackNormal, NORMAL_BIQUADRATIC_WG, 'n');
|
2013-09-21 01:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_hud.AddSlider("Mipmap Bias", 0, 5, 0,
|
|
|
|
-200, 450, 20, false, callbackSlider, 0);
|
2013-10-16 00:47:58 +00:00
|
|
|
g_hud.AddSlider("Displacement", 0, 5, 1,
|
2013-09-21 01:29:00 +00:00
|
|
|
-200, 490, 20, false, callbackSlider, 1);
|
2013-10-16 00:47:58 +00:00
|
|
|
g_hud.AddCheckBox("Seamless Mipmap", g_seamless,
|
|
|
|
-200, 530, callbackCheckBox, HUD_CB_SEAMLESS_MIPMAP, 'j');
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2015-05-14 00:35:46 +00:00
|
|
|
g_hud.Rebuild(windowWidth, windowHeight, g_width, g_height);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// create mesh from ptex metadata
|
2012-08-04 02:51:27 +00:00
|
|
|
createOsdMesh(g_level, g_kernel);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// load ptex files
|
|
|
|
if (colorFilename)
|
2013-10-08 02:06:40 +00:00
|
|
|
g_osdPTexImage = createPtex(colorFilename, colorMem);
|
2012-12-11 01:15:13 +00:00
|
|
|
if (displacementFilename)
|
2013-10-08 02:06:40 +00:00
|
|
|
g_osdPTexDisplacement = createPtex(displacementFilename, displacementMem);
|
2012-12-11 01:15:13 +00:00
|
|
|
if (occlusionFilename)
|
2013-10-08 02:06:40 +00:00
|
|
|
g_osdPTexOcclusion = createPtex(occlusionFilename, occlusionMem);
|
2012-12-11 01:15:13 +00:00
|
|
|
if (specularFilename)
|
2013-10-08 02:06:40 +00:00
|
|
|
g_osdPTexSpecular = createPtex(specularFilename, specularMem);
|
|
|
|
|
|
|
|
g_ptexMemoryUsage =
|
|
|
|
(g_osdPTexImage ? g_osdPTexImage->GetMemoryUsage() : 0)
|
|
|
|
+ (g_osdPTexDisplacement ? g_osdPTexDisplacement->GetMemoryUsage() : 0)
|
|
|
|
+ (g_osdPTexOcclusion ? g_osdPTexOcclusion->GetMemoryUsage() : 0)
|
|
|
|
+ (g_osdPTexSpecular ? g_osdPTexSpecular->GetMemoryUsage() : 0);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
// load animation obj sequences (optional)
|
|
|
|
if (not animobjs.empty()) {
|
|
|
|
for (int i = 0; i < (int)animobjs.size(); ++i) {
|
|
|
|
std::ifstream ifs(animobjs[i].c_str());
|
|
|
|
if (ifs) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << ifs.rdbuf();
|
|
|
|
ifs.close();
|
2013-07-18 22:06:48 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
printf("Reading %s\r", animobjs[i].c_str());
|
|
|
|
std::string str = ss.str();
|
2014-09-05 22:07:46 +00:00
|
|
|
Shape *shape = Shape::parseObj(str.c_str(), kCatmark);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
if (shape->verts.size() != g_positions.size()) {
|
|
|
|
printf("Error: vertex count doesn't match.\n");
|
2013-01-29 23:54:18 +00:00
|
|
|
goto error;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_animPositions.push_back(shape->verts);
|
|
|
|
delete shape;
|
|
|
|
} else {
|
|
|
|
printf("Error in reading %s\n", animobjs[i].c_str());
|
2013-01-29 23:54:18 +00:00
|
|
|
goto error;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diffuseEnvironmentMap) {
|
|
|
|
HdrInfo info;
|
|
|
|
unsigned char * image = loadHdr(diffuseEnvironmentMap, &info, /*convertToFloat=*/true);
|
|
|
|
if (image) {
|
|
|
|
glGenTextures(1, &g_diffuseEnvironmentMap);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_diffuseEnvironmentMap);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, info.width, info.height,
|
|
|
|
0, GL_RGBA, GL_FLOAT, image);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
free(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (specularEnvironmentMap) {
|
|
|
|
HdrInfo info;
|
|
|
|
unsigned char * image = loadHdr(specularEnvironmentMap, &info, /*convertToFloat=*/true);
|
|
|
|
if (image) {
|
|
|
|
glGenTextures(1, &g_specularEnvironmentMap);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_specularEnvironmentMap);
|
2013-01-29 23:54:18 +00:00
|
|
|
// glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); // deprecated
|
2012-12-11 01:15:13 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, info.width, info.height,
|
|
|
|
0, GL_RGBA, GL_FLOAT, image);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2013-01-29 23:54:18 +00:00
|
|
|
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2012-12-11 01:15:13 +00:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
free(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (diffuseEnvironmentMap || specularEnvironmentMap) {
|
|
|
|
createSky();
|
|
|
|
}
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
fitFrame();
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
while (g_running) {
|
|
|
|
idle();
|
|
|
|
display();
|
2013-01-31 23:34:35 +00:00
|
|
|
|
|
|
|
glfwPollEvents();
|
|
|
|
glfwSwapBuffers(g_window);
|
2014-09-05 22:07:46 +00:00
|
|
|
|
2013-01-31 23:34:35 +00:00
|
|
|
glFinish();
|
2013-01-29 23:54:18 +00:00
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
error:
|
2013-01-29 23:54:18 +00:00
|
|
|
uninitGL();
|
|
|
|
glfwTerminate();
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|