2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +00:00
|
|
|
// Copyright 2013 Pixar
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License
|
|
|
|
// and the following modification to it: Section 6 Trademarks.
|
|
|
|
// deleted and replaced with:
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +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 for reproducing
|
|
|
|
// the content of the NOTICE file.
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +00:00
|
|
|
// You may obtain a copy of the License at
|
2012-08-04 02:51:27 +00:00
|
|
|
//
|
2013-07-18 21:19:50 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific
|
|
|
|
// language governing permissions and limitations under the
|
|
|
|
// License.
|
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
|
|
|
|
|
|
|
|
#if defined(GLFW_VERSION_3)
|
2013-06-20 18:53:33 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
2013-09-21 01:29:00 +00:00
|
|
|
GLFWwindow* g_window = 0;
|
|
|
|
GLFWmonitor* g_primary = 0;
|
2013-01-31 23:34:35 +00:00
|
|
|
#else
|
2013-01-29 23:54:18 +00:00
|
|
|
#include <GL/glfw.h>
|
2012-08-04 02:51:27 +00:00
|
|
|
#endif
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <algorithm>
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#define HBR_ADAPTIVE
|
2012-09-18 01:41:48 +00:00
|
|
|
|
|
|
|
#include <hbr/mesh.h>
|
|
|
|
#include <hbr/bilinear.h>
|
|
|
|
#include <hbr/catmark.h>
|
|
|
|
#include <hbr/face.h>
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
#include <osd/error.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/glDrawContext.h>
|
|
|
|
#include <osd/glDrawRegistry.h>
|
2013-09-21 01:29:00 +00:00
|
|
|
#include <osd/glPtexMipmapTexture.h>
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
#include <osd/cpuGLVertexBuffer.h>
|
|
|
|
#include <osd/cpuComputeContext.h>
|
|
|
|
#include <osd/cpuComputeController.h>
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdCpuComputeController * g_cpuComputeController = NULL;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENMP
|
|
|
|
#include <osd/ompComputeController.h>
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdOmpComputeController * g_ompComputeController = NULL;
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/clGLVertexBuffer.h>
|
|
|
|
#include <osd/clComputeContext.h>
|
|
|
|
#include <osd/clComputeController.h>
|
|
|
|
|
|
|
|
#include "../common/clInit.h"
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
cl_context g_clContext = NULL;
|
|
|
|
cl_command_queue g_clQueue = NULL;
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdCLComputeController * g_clComputeController = NULL;
|
2012-08-04 02:51:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_CUDA
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/cudaGLVertexBuffer.h>
|
|
|
|
#include <osd/cudaComputeContext.h>
|
|
|
|
#include <osd/cudaComputeController.h>
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
#include <cuda_runtime_api.h>
|
|
|
|
#include <cuda_gl_interop.h>
|
|
|
|
|
|
|
|
#include "../common/cudaInit.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
bool g_cudaInitialized = false;
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdCudaComputeController * g_cudaComputeController = NULL;
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
|
|
|
|
#include <osd/glslTransformFeedbackComputeContext.h>
|
|
|
|
#include <osd/glslTransformFeedbackComputeController.h>
|
|
|
|
#include <osd/glVertexBuffer.h>
|
2013-09-21 01:29:00 +00:00
|
|
|
OpenSubdiv::OsdGLSLTransformFeedbackComputeController
|
|
|
|
*g_glslTransformFeedbackComputeController = NULL;
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
|
|
|
|
#include <osd/glslComputeContext.h>
|
|
|
|
#include <osd/glslComputeController.h>
|
|
|
|
#include <osd/glVertexBuffer.h>
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdGLSLComputeController * g_glslComputeController = NULL;
|
2012-08-04 02:51:27 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include <osd/glMesh.h>
|
|
|
|
OpenSubdiv::OsdGLMeshInterface *g_mesh;
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
#include "Ptexture.h"
|
|
|
|
#include "PtexUtils.h"
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../common/stopwatch.h"
|
|
|
|
#include "../common/simple_math.h"
|
|
|
|
#include "../common/gl_hud.h"
|
2013-05-22 23:26:02 +00:00
|
|
|
#include "../common/patchColors.h"
|
2012-12-11 01:15:13 +00:00
|
|
|
#include "../common/hdr_reader.h"
|
|
|
|
#include "../../regression/common/shape_utils.h"
|
2012-08-04 02:51:27 +00:00
|
|
|
|
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)
|
|
|
|
#include "shader.inc"
|
|
|
|
#else
|
|
|
|
#include "shader_gl3.inc"
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
;
|
|
|
|
static const char *g_skyShaderSource =
|
|
|
|
#include "skyshader.inc"
|
|
|
|
;
|
2013-03-16 01:03:22 +00:00
|
|
|
static const char *g_imageShaderSource =
|
|
|
|
#include "imageshader.inc"
|
|
|
|
;
|
2012-12-11 01:15:13 +00:00
|
|
|
static std::string g_shaderSource;
|
|
|
|
static const char *g_shaderFilename = NULL;
|
|
|
|
|
|
|
|
typedef OpenSubdiv::HbrMesh<OpenSubdiv::OsdVertex> OsdHbrMesh;
|
|
|
|
typedef OpenSubdiv::HbrVertex<OpenSubdiv::OsdVertex> OsdHbrVertex;
|
|
|
|
typedef OpenSubdiv::HbrFace<OpenSubdiv::OsdVertex> OsdHbrFace;
|
|
|
|
typedef OpenSubdiv::HbrHalfedge<OpenSubdiv::OsdVertex> OsdHbrHalfedge;
|
|
|
|
|
|
|
|
enum KernelType { kCPU = 0,
|
|
|
|
kOPENMP = 1,
|
|
|
|
kCUDA = 2,
|
|
|
|
kCL = 3,
|
|
|
|
kGLSL = 4,
|
|
|
|
kGLSLCompute = 5 };
|
|
|
|
|
|
|
|
enum HudCheckBox { HUD_CB_ADAPTIVE,
|
|
|
|
HUD_CB_DISPLAY_OCCLUSION,
|
|
|
|
HUD_CB_DISPLAY_NORMALMAP,
|
|
|
|
HUD_CB_DISPLAY_SPECULAR,
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
g_mbutton[3] = {0, 0, 0},
|
|
|
|
g_level = 2,
|
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
|
|
|
|
|
|
|
GLuint g_transformUB = 0,
|
|
|
|
g_transformBinding = 0,
|
|
|
|
g_tessellationUB = 0,
|
|
|
|
g_tessellationBinding = 0,
|
|
|
|
g_lightingUB = 0,
|
|
|
|
g_lightingBinding = 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
struct Transform {
|
|
|
|
float ModelViewMatrix[16];
|
|
|
|
float ProjectionMatrix[16];
|
|
|
|
float ModelViewProjectionMatrix[16];
|
|
|
|
float ModelViewInverseMatrix[16];
|
|
|
|
} transformData;
|
|
|
|
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
GLuint g_primQuery = 0;
|
2013-01-29 23:54:18 +00:00
|
|
|
GLuint g_vao = 0;
|
|
|
|
GLuint g_skyVAO = 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
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
struct Sky {
|
|
|
|
int numIndices;
|
|
|
|
GLuint vertexBuffer;
|
|
|
|
GLuint elementBuffer;
|
|
|
|
GLuint mvpMatrix;
|
|
|
|
GLuint program;
|
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),
|
|
|
|
program(0) {}
|
|
|
|
} g_sky;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
struct ImageShader {
|
|
|
|
GLuint blurProgram;
|
|
|
|
GLuint hipassProgram;
|
|
|
|
GLuint compositeProgram;
|
|
|
|
|
|
|
|
GLuint frameBuffer;
|
|
|
|
GLuint frameBufferTexture;
|
|
|
|
GLuint frameBufferDepthTexture;
|
|
|
|
|
|
|
|
GLuint smallFrameBuffer[2];
|
|
|
|
GLuint smallFrameBufferTexture[2];
|
|
|
|
|
|
|
|
GLuint smallWidth, smallHeight;
|
|
|
|
|
|
|
|
GLuint vao;
|
|
|
|
GLuint vbo;
|
|
|
|
|
|
|
|
ImageShader() : blurProgram(0), hipassProgram(0), compositeProgram(0),
|
|
|
|
frameBuffer(0), frameBufferTexture(0), frameBufferDepthTexture(0) {
|
|
|
|
smallFrameBuffer[0] = smallFrameBuffer[1] = 0;
|
|
|
|
smallFrameBufferTexture[0] = smallFrameBufferTexture[1] = 0;
|
|
|
|
}
|
|
|
|
} g_imageShader;
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
OpenSubdiv::OsdGLPtexMipmapTexture * g_osdPTexImage = 0;
|
|
|
|
OpenSubdiv::OsdGLPtexMipmapTexture * g_osdPTexDisplacement = 0;
|
|
|
|
OpenSubdiv::OsdGLPtexMipmapTexture * g_osdPTexOcclusion = 0;
|
|
|
|
OpenSubdiv::OsdGLPtexMipmapTexture * g_osdPTexSpecular = 0;
|
2012-12-11 01:15:13 +00:00
|
|
|
const char * g_ptexColorFilename;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
static void
|
2012-12-11 01:15:13 +00:00
|
|
|
checkGLErrors(std::string const & where = "")
|
|
|
|
{
|
|
|
|
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
|
2013-09-21 01:29:00 +00:00
|
|
|
calcNormals(OsdHbrMesh * mesh, std::vector<float> const & pos, std::vector<float> & result )
|
|
|
|
{
|
2012-08-04 02:51:27 +00:00
|
|
|
// calc normal vectors
|
|
|
|
int nverts = (int)pos.size()/3;
|
|
|
|
|
|
|
|
int nfaces = mesh->GetNumCoarseFaces();
|
|
|
|
for (int i = 0; i < nfaces; ++i) {
|
2012-12-11 01:15:13 +00:00
|
|
|
OsdHbrFace * f = mesh->GetFace(i);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
float const * p0 = &pos[f->GetVertex(0)->GetID()*3],
|
|
|
|
* p1 = &pos[f->GetVertex(1)->GetID()*3],
|
|
|
|
* p2 = &pos[f->GetVertex(2)->GetID()*3];
|
|
|
|
|
|
|
|
float n[3];
|
2013-09-21 01:29:00 +00:00
|
|
|
cross(n, p0, p1, p2);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < f->GetNumVertices(); j++) {
|
|
|
|
int idx = f->GetVertex(j)->GetID() * 3;
|
|
|
|
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
|
2013-09-21 01:29:00 +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
|
2013-09-21 01:29:00 +00:00
|
|
|
fitFrame()
|
|
|
|
{
|
2012-08-04 02:51:27 +00:00
|
|
|
g_pan[0] = g_pan[1] = 0;
|
|
|
|
g_dolly = g_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
template <class T>
|
|
|
|
OpenSubdiv::HbrMesh<T> * createPTexGeo(PtexTexture * r)
|
|
|
|
{
|
|
|
|
PtexMetaData* meta = r->getMetaData();
|
2013-09-21 01:29:00 +00:00
|
|
|
if (meta->numKeys() < 3) return NULL;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
const float* vp;
|
|
|
|
const int *vi, *vc;
|
|
|
|
int nvp, nvi, nvc;
|
|
|
|
|
|
|
|
meta->getValue("PtexFaceVertCounts", vc, nvc);
|
2013-09-21 01:29:00 +00:00
|
|
|
if (nvc == 0)
|
2012-08-04 02:51:27 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
meta->getValue("PtexVertPositions", vp, nvp);
|
2013-09-21 01:29:00 +00:00
|
|
|
if (nvp == 0)
|
2012-08-04 02:51:27 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
meta->getValue("PtexFaceVertIndices", vi, nvi);
|
2013-09-21 01:29:00 +00:00
|
|
|
if (nvi == 0)
|
2012-08-04 02:51:27 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
static OpenSubdiv::HbrCatmarkSubdivision<T> _catmark;
|
|
|
|
static OpenSubdiv::HbrBilinearSubdivision<T> _bilinear;
|
|
|
|
OpenSubdiv::HbrMesh<T> * mesh;
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_scheme == 0)
|
2012-08-04 02:51:27 +00:00
|
|
|
mesh = new OpenSubdiv::HbrMesh<T>(&_catmark);
|
|
|
|
else
|
|
|
|
mesh = new OpenSubdiv::HbrMesh<T>(&_bilinear);
|
|
|
|
|
|
|
|
g_positions.clear();
|
|
|
|
g_positions.reserve(nvp);
|
|
|
|
|
|
|
|
// compute model bounding
|
|
|
|
float min[3] = {vp[0], vp[1], vp[2]};
|
|
|
|
float max[3] = {vp[0], vp[1], vp[2]};
|
2013-09-21 01:29:00 +00:00
|
|
|
for (int i = 0; i < nvp/3; ++i) {
|
|
|
|
for (int j = 0; j < 3; ++j) {
|
2012-08-04 02:51:27 +00:00
|
|
|
float v = vp[i*3+j];
|
|
|
|
g_positions.push_back(v);
|
|
|
|
min[j] = std::min(min[j], v);
|
|
|
|
max[j] = std::max(max[j], v);
|
|
|
|
}
|
|
|
|
mesh->NewVertex(i, T());
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
for (int j = 0; j < 3; ++j) {
|
2012-08-04 02:51:27 +00:00
|
|
|
g_center[j] = (min[j] + max[j]) * 0.5f;
|
|
|
|
g_size += (max[j]-min[j])*(max[j]-min[j]);
|
|
|
|
}
|
|
|
|
g_size = sqrtf(g_size);
|
|
|
|
|
|
|
|
const int *fv = vi;
|
2013-09-21 01:29:00 +00:00
|
|
|
for (int i = 0, ptxidx = 0; i < nvc; ++i) {
|
2012-08-04 02:51:27 +00:00
|
|
|
int nv = vc[i];
|
|
|
|
OpenSubdiv::HbrFace<T> * face = mesh->NewFace(nv, (int *)fv, 0);
|
|
|
|
|
|
|
|
face->SetPtexIndex(ptxidx);
|
2013-09-21 01:29:00 +00:00
|
|
|
if (nv != 4)
|
|
|
|
ptxidx += nv;
|
2012-08-04 02:51:27 +00:00
|
|
|
else
|
|
|
|
ptxidx++;
|
|
|
|
|
|
|
|
fv += nv;
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
mesh->SetInterpolateBoundaryMethod(OpenSubdiv::HbrMesh<T>::k_InterpolateBoundaryEdgeOnly);
|
2012-08-04 02:51:27 +00:00
|
|
|
// set creases here
|
|
|
|
// applyTags<T>( mesh, sh );
|
|
|
|
mesh->Finish();
|
|
|
|
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
|
|
|
reshape(GLFWwindow *, int width, int height)
|
2013-01-31 23:34:35 +00:00
|
|
|
#else
|
2013-09-21 01:29:00 +00:00
|
|
|
reshape(int width, int height)
|
2013-01-31 23:34:35 +00:00
|
|
|
#endif
|
2013-09-21 01:29:00 +00:00
|
|
|
{
|
2012-08-04 02:51:27 +00:00
|
|
|
g_width = width;
|
|
|
|
g_height = height;
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
g_hud.Rebuild(width, height);
|
2013-03-16 01:03:22 +00:00
|
|
|
|
|
|
|
// resize framebuffers
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.frameBufferTexture);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.frameBufferDepthTexture);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, width, height, 0,
|
|
|
|
GL_DEPTH_COMPONENT, GL_FLOAT, 0);
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, g_imageShader.frameBuffer);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
|
|
|
GL_TEXTURE_2D, g_imageShader.frameBufferTexture, 0);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
|
|
GL_TEXTURE_2D, g_imageShader.frameBufferDepthTexture, 0);
|
|
|
|
|
|
|
|
const int d = 4;
|
|
|
|
g_imageShader.smallWidth = width/d;
|
|
|
|
g_imageShader.smallHeight = height/d;
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.smallFrameBufferTexture[i]);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width/d, height/d, 0,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, g_imageShader.smallFrameBuffer[i]);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
|
|
|
GL_TEXTURE_2D, g_imageShader.smallFrameBufferTexture[i], 0);
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
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() {
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
2013-03-16 01:03:22 +00:00
|
|
|
reshape(g_window, g_width, g_height);
|
|
|
|
#else
|
|
|
|
reshape(g_width, g_height);
|
|
|
|
#endif
|
|
|
|
}
|
2013-03-19 21:31:44 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
2013-03-19 21:31:44 +00:00
|
|
|
void windowClose(GLFWwindow*) {
|
|
|
|
g_running = false;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int windowClose() {
|
|
|
|
g_running = false;
|
|
|
|
return GL_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2013-09-21 01:29:00 +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
|
|
|
static GLuint compileShader(GLenum shaderType,
|
|
|
|
OpenSubdiv::OsdDrawShaderSource const & common,
|
|
|
|
OpenSubdiv::OsdDrawShaderSource const & source)
|
2012-08-04 02:51:27 +00:00
|
|
|
{
|
2012-12-11 01:15:13 +00:00
|
|
|
const char *sources[4];
|
|
|
|
std::stringstream definitions;
|
2013-09-21 01:29:00 +00:00
|
|
|
for (int i = 0; i < (int)common.defines.size(); ++i) {
|
2012-12-11 01:15:13 +00:00
|
|
|
definitions << "#define "
|
|
|
|
<< common.defines[i].first << " "
|
|
|
|
<< common.defines[i].second << "\n";
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
for (int i = 0; i < (int)source.defines.size(); ++i) {
|
2012-12-11 01:15:13 +00:00
|
|
|
definitions << "#define "
|
|
|
|
<< source.defines[i].first << " "
|
|
|
|
<< source.defines[i].second << "\n";
|
|
|
|
}
|
|
|
|
std::string defString = definitions.str();
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
sources[0] = source.version.c_str();
|
|
|
|
sources[1] = defString.c_str();
|
2012-12-11 01:15:13 +00:00
|
|
|
sources[2] = common.source.c_str();
|
|
|
|
sources[3] = source.source.c_str();
|
2012-08-04 02:51:27 +00:00
|
|
|
|
|
|
|
GLuint shader = glCreateShader(shaderType);
|
2012-12-11 01:15:13 +00:00
|
|
|
glShaderSource(shader, 4, sources, NULL);
|
2012-08-04 02:51:27 +00:00
|
|
|
glCompileShader(shader);
|
|
|
|
|
|
|
|
GLint status;
|
|
|
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
|
2013-09-21 01:29:00 +00:00
|
|
|
if (status == GL_FALSE) {
|
2012-12-11 01:15:13 +00:00
|
|
|
GLchar emsg[40960];
|
2012-08-04 02:51:27 +00:00
|
|
|
glGetShaderInfoLog(shader, sizeof(emsg), 0, emsg);
|
2013-09-21 01:29:00 +00:00
|
|
|
fprintf(stderr, "Error compiling GLSL shader: %s\n", emsg);
|
2012-12-11 01:15:13 +00:00
|
|
|
fprintf(stderr, "Defines: %s\n", defString.c_str());
|
|
|
|
return 0;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return shader;
|
|
|
|
}
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
int bindPTexture(GLint program, OpenSubdiv::OsdGLPtexMipmapTexture *osdPTex,
|
|
|
|
GLuint data, GLuint packing, int samplerUnit)
|
2012-08-04 02:51:27 +00:00
|
|
|
{
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_separate_shader_objects) || defined(GL_VERSION_4_1)
|
2012-12-11 01:15:13 +00:00
|
|
|
glProgramUniform1i(program, data, samplerUnit + 0);
|
2013-01-29 23:54:18 +00:00
|
|
|
glProgramUniform1i(program, packing, samplerUnit + 1);
|
|
|
|
#else
|
|
|
|
glUniform1i(data, samplerUnit + 0);
|
|
|
|
glUniform1i(packing, samplerUnit + 1);
|
|
|
|
#endif
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0 + samplerUnit + 0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D_ARRAY, osdPTex->GetTexelsTexture());
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0 + samplerUnit + 1);
|
|
|
|
glBindTexture(GL_TEXTURE_BUFFER, osdPTex->GetLayoutTextureBuffer());
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
return samplerUnit + 2;
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
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
|
|
|
|
2013-05-09 20:48:00 +00:00
|
|
|
typedef std::pair<OpenSubdiv::OsdDrawContext::PatchDescriptor, Effect> EffectDesc;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
class EffectDrawRegistry : public OpenSubdiv::OsdGLDrawRegistry<EffectDesc>
|
|
|
|
{
|
|
|
|
protected:
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual ConfigType *
|
|
|
|
_CreateDrawConfig(DescType const & desc, SourceConfigType const * sconfig);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
virtual SourceConfigType *
|
|
|
|
_CreateDrawSourceConfig(DescType const & desc);
|
|
|
|
};
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
EffectDrawRegistry::SourceConfigType *
|
|
|
|
EffectDrawRegistry::_CreateDrawSourceConfig(DescType const & desc)
|
|
|
|
{
|
|
|
|
Effect effect = desc.second;
|
|
|
|
|
|
|
|
SourceConfigType * sconfig =
|
|
|
|
BaseRegistry::_CreateDrawSourceConfig(desc.first);
|
|
|
|
|
|
|
|
if (effect.patchCull)
|
|
|
|
sconfig->commonShader.AddDefine("OSD_ENABLE_PATCH_CULL");
|
|
|
|
if (effect.screenSpaceTess)
|
|
|
|
sconfig->commonShader.AddDefine("OSD_ENABLE_SCREENSPACE_TESSELLATION");
|
2013-06-27 20:34:25 +00:00
|
|
|
if (effect.fractionalSpacing)
|
|
|
|
sconfig->commonShader.AddDefine("OSD_FRACTIONAL_ODD_SPACING");
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
|
|
|
const char *glslVersion = "#version 400\n";
|
|
|
|
#else
|
|
|
|
const char *glslVersion = "#version 330\n";
|
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
bool quad = true;
|
2013-05-09 20:48:00 +00:00
|
|
|
if (desc.first.GetType() == OpenSubdiv::FarPatchTables::QUADS) {
|
2012-12-11 01:15:13 +00:00
|
|
|
sconfig->vertexShader.source = g_shaderSource;
|
2013-01-29 23:54:18 +00:00
|
|
|
sconfig->vertexShader.version = glslVersion;
|
2012-12-11 01:15:13 +00:00
|
|
|
sconfig->vertexShader.AddDefine("VERTEX_SHADER");
|
|
|
|
if (effect.displacement) {
|
|
|
|
sconfig->geometryShader.AddDefine("FLAT_NORMALS");
|
|
|
|
}
|
2013-05-09 20:48:00 +00:00
|
|
|
} else {
|
|
|
|
quad = false;
|
|
|
|
sconfig->tessEvalShader.source = g_shaderSource + sconfig->tessEvalShader.source;
|
|
|
|
sconfig->tessEvalShader.version = glslVersion;
|
|
|
|
if (effect.displacement and (not effect.normal))
|
|
|
|
sconfig->geometryShader.AddDefine("FLAT_NORMALS");
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
assert(sconfig);
|
|
|
|
|
|
|
|
sconfig->geometryShader.source = g_shaderSource;
|
2013-01-29 23:54:18 +00:00
|
|
|
sconfig->geometryShader.version = glslVersion;
|
2012-12-11 01:15:13 +00:00
|
|
|
sconfig->geometryShader.AddDefine("GEOMETRY_SHADER");
|
|
|
|
|
|
|
|
sconfig->fragmentShader.source = g_shaderSource;
|
2013-01-29 23:54:18 +00:00
|
|
|
sconfig->fragmentShader.version = glslVersion;
|
2012-12-11 01:15:13 +00:00
|
|
|
sconfig->fragmentShader.AddDefine("FRAGMENT_SHADER");
|
2013-09-21 01:29:00 +00:00
|
|
|
|
|
|
|
switch (effect.color) {
|
|
|
|
case COLOR_NONE:
|
|
|
|
break;
|
|
|
|
case COLOR_PTEX_NEAREST:
|
|
|
|
sconfig->fragmentShader.AddDefine("COLOR_PTEX_NEAREST");
|
|
|
|
break;
|
|
|
|
case COLOR_PTEX_HW_BILINEAR:
|
|
|
|
sconfig->fragmentShader.AddDefine("COLOR_PTEX_HW_BILINEAR");
|
|
|
|
break;
|
|
|
|
case COLOR_PTEX_BILINEAR:
|
|
|
|
sconfig->fragmentShader.AddDefine("COLOR_PTEX_BILINEAR");
|
|
|
|
break;
|
|
|
|
case COLOR_PTEX_BIQUADRATIC:
|
|
|
|
sconfig->fragmentShader.AddDefine("COLOR_PTEX_BIQUADRATIC");
|
|
|
|
break;
|
|
|
|
case COLOR_PATCHTYPE:
|
|
|
|
sconfig->fragmentShader.AddDefine("COLOR_PATCHTYPE");
|
|
|
|
break;
|
|
|
|
case COLOR_PATCHCOORD:
|
|
|
|
sconfig->fragmentShader.AddDefine("COLOR_PATCHCOORD");
|
|
|
|
break;
|
|
|
|
case COLOR_NORMAL:
|
|
|
|
sconfig->fragmentShader.AddDefine("COLOR_NORMAL");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (effect.displacement) {
|
|
|
|
case DISPLACEMENT_NONE:
|
|
|
|
break;
|
|
|
|
case DISPLACEMENT_HW_BILINEAR:
|
|
|
|
sconfig->commonShader.AddDefine("DISPLACEMENT_HW_BILINEAR");
|
|
|
|
break;
|
|
|
|
case DISPLACEMENT_BILINEAR:
|
|
|
|
sconfig->commonShader.AddDefine("DISPLACEMENT_BILINEAR");
|
|
|
|
break;
|
|
|
|
case DISPLACEMENT_BIQUADRATIC:
|
|
|
|
sconfig->commonShader.AddDefine("DISPLACEMENT_BIQUADRATIC");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (effect.normal) {
|
|
|
|
case NORMAL_FACET:
|
|
|
|
sconfig->commonShader.AddDefine("NORMAL_FACET");
|
|
|
|
break;
|
|
|
|
case NORMAL_HW_SCREENSPACE:
|
|
|
|
sconfig->commonShader.AddDefine("NORMAL_HW_SCREENSPACE");
|
|
|
|
break;
|
|
|
|
case NORMAL_SCREENSPACE:
|
|
|
|
sconfig->commonShader.AddDefine("NORMAL_SCREENSPACE");
|
|
|
|
break;
|
|
|
|
case NORMAL_BIQUADRATIC:
|
|
|
|
sconfig->commonShader.AddDefine("NORMAL_BIQUADRATIC");
|
|
|
|
break;
|
|
|
|
case NORMAL_BIQUADRATIC_WG:
|
|
|
|
sconfig->commonShader.AddDefine("OSD_COMPUTE_NORMAL_DERIVATIVES");
|
|
|
|
sconfig->commonShader.AddDefine("NORMAL_BIQUADRATIC_WG");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (effect.occlusion)
|
|
|
|
sconfig->fragmentShader.AddDefine("USE_PTEX_OCCLUSION");
|
|
|
|
if (effect.specular)
|
|
|
|
sconfig->fragmentShader.AddDefine("USE_PTEX_SPECULAR");
|
|
|
|
if (effect.ibl)
|
|
|
|
sconfig->fragmentShader.AddDefine("USE_IBL");
|
|
|
|
|
|
|
|
if (quad) {
|
|
|
|
sconfig->geometryShader.AddDefine("PRIM_QUAD");
|
|
|
|
sconfig->fragmentShader.AddDefine("PRIM_QUAD");
|
|
|
|
} else {
|
|
|
|
sconfig->geometryShader.AddDefine("PRIM_TRI");
|
|
|
|
sconfig->fragmentShader.AddDefine("PRIM_TRI");
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (effect.wire == 0) {
|
|
|
|
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_WIRE");
|
|
|
|
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_WIRE");
|
|
|
|
} else if (effect.wire == 1) {
|
|
|
|
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_FILL");
|
|
|
|
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_FILL");
|
|
|
|
} else if (effect.wire == 2) {
|
|
|
|
sconfig->geometryShader.AddDefine("GEOMETRY_OUT_LINE");
|
|
|
|
sconfig->fragmentShader.AddDefine("GEOMETRY_OUT_LINE");
|
2013-09-21 01:29:00 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
return sconfig;
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
EffectDrawRegistry::ConfigType *
|
|
|
|
EffectDrawRegistry::_CreateDrawConfig(
|
|
|
|
DescType const & desc,
|
|
|
|
SourceConfigType const * sconfig)
|
|
|
|
{
|
|
|
|
ConfigType * config = BaseRegistry::_CreateDrawConfig(desc.first, sconfig);
|
|
|
|
assert(config);
|
|
|
|
|
|
|
|
// XXXdyu can use layout(binding=) with GLSL 4.20 and beyond
|
|
|
|
g_transformBinding = 0;
|
2013-09-21 01:29:00 +00:00
|
|
|
GLint transformIndex = glGetUniformBlockIndex(config->program, "Transform");
|
|
|
|
if (transformIndex != -1)
|
|
|
|
glUniformBlockBinding(config->program, transformIndex, g_transformBinding);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
g_tessellationBinding = 1;
|
2013-01-29 23:54:18 +00:00
|
|
|
|
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
2013-09-21 01:29:00 +00:00
|
|
|
GLint tessellationIndex = glGetUniformBlockIndex(config->program, "Tessellation");
|
|
|
|
if (tessellationIndex != -1)
|
|
|
|
glUniformBlockBinding(config->program, tessellationIndex, g_tessellationBinding);
|
2013-01-29 23:54:18 +00:00
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
g_lightingBinding = 2;
|
2013-09-21 01:29:00 +00:00
|
|
|
GLint lightingIndex = glGetUniformBlockIndex(config->program, "Lighting");
|
|
|
|
if (lightingIndex != -1)
|
|
|
|
glUniformBlockBinding(config->program, lightingIndex, g_lightingBinding);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
GLint loc;
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_separate_shader_objects) || defined(GL_VERSION_4_1)
|
2013-07-18 19:57:26 +00:00
|
|
|
if ((loc = glGetUniformLocation(config->program, "OsdVertexBuffer")) != -1) {
|
2013-09-21 01:29:00 +00:00
|
|
|
glProgramUniform1i(config->program, loc, 0); // GL_TEXTURE0
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-07-18 19:57:26 +00:00
|
|
|
if ((loc = glGetUniformLocation(config->program, "OsdValenceBuffer")) != -1) {
|
2013-09-21 01:29:00 +00:00
|
|
|
glProgramUniform1i(config->program, loc, 1); // GL_TEXTURE1
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-07-18 19:57:26 +00:00
|
|
|
if ((loc = glGetUniformLocation(config->program, "OsdQuadOffsetBuffer")) != -1) {
|
2013-09-21 01:29:00 +00:00
|
|
|
glProgramUniform1i(config->program, loc, 2); // GL_TEXTURE2
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-07-18 19:57:26 +00:00
|
|
|
if ((loc = glGetUniformLocation(config->program, "OsdPatchParamBuffer")) != -1) {
|
2013-09-21 01:29:00 +00:00
|
|
|
glProgramUniform1i(config->program, loc, 3); // GL_TEXTURE3
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
|
|
|
glUseProgram(config->program);
|
2013-07-18 19:57:26 +00:00
|
|
|
if ((loc = glGetUniformLocation(config->program, "OsdVertexBuffer")) != -1) {
|
2013-09-21 01:29:00 +00:00
|
|
|
glUniform1i(loc, 0); // GL_TEXTURE0
|
2013-01-29 23:54:18 +00:00
|
|
|
}
|
2013-07-18 19:57:26 +00:00
|
|
|
if ((loc = glGetUniformLocation(config->program, "OsdValenceBuffer")) != -1) {
|
2013-09-21 01:29:00 +00:00
|
|
|
glUniform1i(loc, 1); // GL_TEXTURE1
|
2013-01-29 23:54:18 +00:00
|
|
|
}
|
2013-07-18 19:57:26 +00:00
|
|
|
if ((loc = glGetUniformLocation(config->program, "OsdQuadOffsetBuffer")) != -1) {
|
2013-09-21 01:29:00 +00:00
|
|
|
glUniform1i(loc, 2); // GL_TEXTURE2
|
2013-01-29 23:54:18 +00:00
|
|
|
}
|
2013-07-18 19:57:26 +00:00
|
|
|
if ((loc = glGetUniformLocation(config->program, "OsdPatchParamBuffer")) != -1) {
|
2013-09-21 01:29:00 +00:00
|
|
|
glUniform1i(loc, 3); // GL_TEXTURE3
|
2013-01-29 23:54:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
return config;
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
EffectDrawRegistry effectRegistry;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
EffectDrawRegistry::ConfigType *
|
2013-09-21 01:29:00 +00:00
|
|
|
getInstance(Effect effect, OpenSubdiv::OsdDrawContext::PatchDescriptor const & patchDesc)
|
|
|
|
{
|
2013-05-09 20:48:00 +00:00
|
|
|
EffectDesc desc(patchDesc, effect);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
EffectDrawRegistry::ConfigType * config =
|
|
|
|
effectRegistry.GetDrawConfig(desc);
|
|
|
|
assert(config);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
return config;
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2013-09-21 01:29:00 +00:00
|
|
|
OpenSubdiv::OsdGLPtexMipmapTexture *
|
|
|
|
createPtex(const char *filename)
|
|
|
|
{
|
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-09-21 01:29:00 +00:00
|
|
|
OpenSubdiv::OsdGLPtexMipmapTexture *osdPtex =
|
|
|
|
OpenSubdiv::OsdGLPtexMipmapTexture::Create(ptex, g_maxMipmapLevels);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-26 16:31:54 +00:00
|
|
|
#ifdef USE_PTEX_CACHE
|
|
|
|
cache->release();
|
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
ptex->release();
|
2013-09-26 16:31:54 +00:00
|
|
|
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
return osdPtex;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-21 01:29:00 +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
|
|
|
|
|
|
|
// generate Hbr representation from ptex
|
2012-12-11 01:15:13 +00:00
|
|
|
OsdHbrMesh * hmesh = createPTexGeo<OpenSubdiv::OsdVertex>(ptexColor);
|
2013-09-21 01:29:00 +00:00
|
|
|
if (hmesh == NULL) return;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
g_normals.resize(g_positions.size(), 0.0f);
|
|
|
|
calcNormals(hmesh, 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
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
OpenSubdiv::OsdMeshBitset bits;
|
|
|
|
bits.set(OpenSubdiv::MeshAdaptive, doAdaptive);
|
|
|
|
bits.set(OpenSubdiv::MeshPtexData, 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) {
|
2013-02-20 01:33:32 +00:00
|
|
|
if (not g_cpuComputeController) {
|
|
|
|
g_cpuComputeController = new OpenSubdiv::OsdCpuComputeController();
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
g_mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCpuGLVertexBuffer,
|
|
|
|
OpenSubdiv::OsdCpuComputeController,
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdGLDrawContext>(
|
|
|
|
g_cpuComputeController,
|
2013-06-27 19:57:21 +00:00
|
|
|
hmesh,
|
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENMP
|
|
|
|
} else if (kernel == kOPENMP) {
|
2013-02-20 01:33:32 +00:00
|
|
|
if (not g_ompComputeController) {
|
|
|
|
g_ompComputeController = new OpenSubdiv::OsdOmpComputeController();
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
g_mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCpuGLVertexBuffer,
|
|
|
|
OpenSubdiv::OsdOmpComputeController,
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdGLDrawContext>(
|
|
|
|
g_ompComputeController,
|
2013-06-27 19:57:21 +00:00
|
|
|
hmesh,
|
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits);
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2013-09-21 01:29:00 +00:00
|
|
|
} else if (kernel == kCL) {
|
2013-02-20 01:33:32 +00:00
|
|
|
if (not g_clComputeController) {
|
|
|
|
g_clComputeController = new OpenSubdiv::OsdCLComputeController(g_clContext, g_clQueue);
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
g_mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCLGLVertexBuffer,
|
|
|
|
OpenSubdiv::OsdCLComputeController,
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdGLDrawContext>(
|
|
|
|
g_clComputeController,
|
2013-06-27 19:57:21 +00:00
|
|
|
hmesh,
|
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits, g_clContext, g_clQueue);
|
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) {
|
2013-02-20 01:33:32 +00:00
|
|
|
if (not g_cudaComputeController) {
|
|
|
|
g_cudaComputeController = new OpenSubdiv::OsdCudaComputeController();
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
g_mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdCudaGLVertexBuffer,
|
|
|
|
OpenSubdiv::OsdCudaComputeController,
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdGLDrawContext>(
|
|
|
|
g_cudaComputeController,
|
2013-06-27 19:57:21 +00:00
|
|
|
hmesh,
|
|
|
|
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) {
|
2013-05-20 19:16:08 +00:00
|
|
|
if (not g_glslTransformFeedbackComputeController) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_glslTransformFeedbackComputeController =
|
|
|
|
new OpenSubdiv::OsdGLSLTransformFeedbackComputeController();
|
2013-02-20 01:33:32 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
g_mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdGLVertexBuffer,
|
|
|
|
OpenSubdiv::OsdGLSLTransformFeedbackComputeController,
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdGLDrawContext>(
|
|
|
|
g_glslTransformFeedbackComputeController,
|
2013-06-27 19:57:21 +00:00
|
|
|
hmesh,
|
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits);
|
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) {
|
2013-02-20 01:33:32 +00:00
|
|
|
if (not g_glslComputeController) {
|
|
|
|
g_glslComputeController = new OpenSubdiv::OsdGLSLComputeController();
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
g_mesh = new OpenSubdiv::OsdMesh<OpenSubdiv::OsdGLVertexBuffer,
|
|
|
|
OpenSubdiv::OsdGLSLComputeController,
|
2013-02-20 01:33:32 +00:00
|
|
|
OpenSubdiv::OsdGLDrawContext>(
|
|
|
|
g_glslComputeController,
|
2013-06-27 19:57:21 +00:00
|
|
|
hmesh,
|
|
|
|
numVertexElements,
|
|
|
|
numVaryingElements,
|
|
|
|
level, bits);
|
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
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
delete hmesh;
|
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
|
|
|
|
|
|
|
glBindVertexArray(0);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-21 01:29:00 +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();
|
|
|
|
|
|
|
|
g_sky.program = glCreateProgram();
|
|
|
|
|
|
|
|
OpenSubdiv::OsdDrawShaderSource common, vertexShader, fragmentShader;
|
|
|
|
vertexShader.source = g_skyShaderSource;
|
|
|
|
vertexShader.version = "#version 410\n";
|
|
|
|
vertexShader.AddDefine("SKY_VERTEX_SHADER");
|
|
|
|
fragmentShader.source = g_skyShaderSource;
|
|
|
|
fragmentShader.version = "#version 410\n";
|
|
|
|
fragmentShader.AddDefine("SKY_FRAGMENT_SHADER");
|
2013-09-21 01:29:00 +00:00
|
|
|
GLuint vs = compileShader(GL_VERTEX_SHADER,
|
2012-12-11 01:15:13 +00:00
|
|
|
common, vertexShader);
|
|
|
|
GLuint fs = compileShader(GL_FRAGMENT_SHADER,
|
|
|
|
common, fragmentShader);
|
|
|
|
|
|
|
|
glAttachShader(g_sky.program, vs);
|
|
|
|
glAttachShader(g_sky.program, fs);
|
|
|
|
glLinkProgram(g_sky.program);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glDeleteShader(vs);
|
|
|
|
glDeleteShader(fs);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
GLint environmentMap = glGetUniformLocation(g_sky.program, "environmentMap");
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_separate_shader_objects) || defined(GL_VERSION_4_1)
|
2012-12-11 01:15:13 +00:00
|
|
|
if (g_specularEnvironmentMap)
|
|
|
|
glProgramUniform1i(g_sky.program, environmentMap, 6);
|
|
|
|
else
|
|
|
|
glProgramUniform1i(g_sky.program, environmentMap, 5);
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
|
|
|
glUseProgram(g_sky.program);
|
|
|
|
if (g_specularEnvironmentMap)
|
|
|
|
glUniform1i(environmentMap, 6);
|
|
|
|
else
|
|
|
|
glUniform1i(environmentMap, 5);
|
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
g_sky.mvpMatrix = glGetUniformLocation(g_sky.program, "ModelViewProjectionMatrix");
|
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
GLuint
|
2013-09-21 01:29:00 +00:00
|
|
|
compileImageShader(const char *define)
|
|
|
|
{
|
2013-03-16 01:03:22 +00:00
|
|
|
GLuint program = glCreateProgram();
|
|
|
|
|
|
|
|
OpenSubdiv::OsdDrawShaderSource common, vertexShader, fragmentShader;
|
|
|
|
vertexShader.source = g_imageShaderSource;
|
|
|
|
vertexShader.version = "#version 410\n";
|
|
|
|
vertexShader.AddDefine("IMAGE_VERTEX_SHADER");
|
|
|
|
fragmentShader.source = g_imageShaderSource;
|
|
|
|
fragmentShader.version = "#version 410\n";
|
|
|
|
fragmentShader.AddDefine("IMAGE_FRAGMENT_SHADER");
|
|
|
|
fragmentShader.AddDefine(define);
|
|
|
|
|
|
|
|
GLuint vs = compileShader(GL_VERTEX_SHADER,
|
|
|
|
common, vertexShader);
|
|
|
|
GLuint fs = compileShader(GL_FRAGMENT_SHADER,
|
|
|
|
common, fragmentShader);
|
|
|
|
|
|
|
|
glAttachShader(program, vs);
|
|
|
|
glAttachShader(program, fs);
|
|
|
|
glLinkProgram(program);
|
|
|
|
|
|
|
|
glDeleteShader(vs);
|
|
|
|
glDeleteShader(fs);
|
|
|
|
|
2013-07-18 19:57:26 +00:00
|
|
|
#if defined(GL_ARB_separate_shader_objects) || defined(GL_VERSION_4_1)
|
2013-03-16 01:03:22 +00:00
|
|
|
GLint colorMap = glGetUniformLocation(program, "colorMap");
|
|
|
|
if (colorMap != -1)
|
|
|
|
glProgramUniform1i(program, colorMap, 0); // GL_TEXTURE0
|
|
|
|
GLint depthMap = glGetUniformLocation(program, "depthMap");
|
|
|
|
if (depthMap != -1)
|
|
|
|
glProgramUniform1i(program, depthMap, 1); // GL_TEXTURE1
|
2013-07-18 19:57:26 +00:00
|
|
|
#else
|
|
|
|
glUseProgram(program);
|
|
|
|
GLint colorMap = glGetUniformLocation(program, "colorMap");
|
|
|
|
if (colorMap != -1)
|
|
|
|
glUniform1i(colorMap, 0); // GL_TEXTURE0
|
|
|
|
GLint depthMap = glGetUniformLocation(program, "depthMap");
|
|
|
|
if (depthMap != -1)
|
|
|
|
glUniform1i(depthMap, 1); // GL_TEXTURE1
|
|
|
|
#endif
|
2013-03-16 01:03:22 +00:00
|
|
|
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-21 01:29:00 +00:00
|
|
|
createImageShader()
|
|
|
|
{
|
2013-03-16 01:03:22 +00:00
|
|
|
g_imageShader.blurProgram = compileImageShader("BLUR");
|
|
|
|
g_imageShader.hipassProgram = compileImageShader("HIPASS");
|
|
|
|
g_imageShader.compositeProgram = compileImageShader("COMPOSITE");
|
|
|
|
|
|
|
|
glGenVertexArrays(1, &g_imageShader.vao);
|
|
|
|
glBindVertexArray(g_imageShader.vao);
|
|
|
|
glGenBuffers(1, &g_imageShader.vbo);
|
|
|
|
float pos[] = { -1, -1, 1, -1, -1, 1, 1, 1 };
|
|
|
|
glGenBuffers(1, &g_imageShader.vbo);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_imageShader.vbo);
|
|
|
|
glBufferData(GL_ARRAY_BUFFER,
|
|
|
|
sizeof(pos), pos, GL_STATIC_DRAW);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, g_imageShader.vbo);
|
|
|
|
|
|
|
|
glEnableVertexAttribArray(0);
|
|
|
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-21 01:29:00 +00:00
|
|
|
applyImageShader()
|
|
|
|
{
|
2013-03-16 01:03:22 +00:00
|
|
|
int w = g_imageShader.smallWidth, h = g_imageShader.smallHeight;
|
|
|
|
const float hoffsets[10] = {
|
|
|
|
-2.0f / w, 0,
|
|
|
|
-1.0f / w, 0,
|
|
|
|
0, 0,
|
|
|
|
+1.0f / w, 0,
|
|
|
|
+2.0f / w, 0,
|
|
|
|
};
|
|
|
|
const float voffsets[10] = {
|
|
|
|
0, -2.0f / h,
|
|
|
|
0, -1.0f / h,
|
|
|
|
0, 0,
|
|
|
|
0, +1.0f / h,
|
|
|
|
0, +2.0f / h,
|
|
|
|
};
|
|
|
|
const float weights[5] = {
|
|
|
|
1.0f / 16.0f,
|
|
|
|
4.0f / 16.0f,
|
|
|
|
6.0f / 16.0f,
|
|
|
|
4.0f / 16.0f,
|
|
|
|
1.0f / 16.0f,
|
|
|
|
};
|
|
|
|
|
|
|
|
checkGLErrors("image shader begin");
|
|
|
|
glBindVertexArray(g_imageShader.vao);
|
|
|
|
|
|
|
|
GLint uniformAlpha = glGetUniformLocation(g_imageShader.compositeProgram, "alpha");
|
|
|
|
|
|
|
|
if (g_bloom) {
|
|
|
|
// XXX: fix me
|
|
|
|
GLint uniformOffsets = glGetUniformLocation(g_imageShader.blurProgram, "Offsets");
|
|
|
|
GLint uniformWeights = glGetUniformLocation(g_imageShader.blurProgram, "Weights");
|
|
|
|
|
|
|
|
// down sample
|
|
|
|
glUseProgram(g_imageShader.hipassProgram);
|
|
|
|
glViewport(0, 0, g_imageShader.smallWidth, g_imageShader.smallHeight);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, g_imageShader.smallFrameBuffer[0]);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.frameBufferTexture);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
// horizontal blur pass
|
|
|
|
glUseProgram(g_imageShader.blurProgram);
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, g_imageShader.smallFrameBuffer[1]);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.smallFrameBufferTexture[0]);
|
|
|
|
glUniform2fv(uniformOffsets, 5, hoffsets);
|
|
|
|
glUniform1fv(uniformWeights, 5, weights);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
// vertical blur pass
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, g_imageShader.smallFrameBuffer[0]);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.smallFrameBufferTexture[1]);
|
|
|
|
glUniform2fv(uniformOffsets, 5, voffsets);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
glViewport(0, 0, g_width, g_height);
|
|
|
|
|
|
|
|
// blit full-res
|
|
|
|
glUseProgram(g_imageShader.compositeProgram);
|
|
|
|
glUniform1f(uniformAlpha, 1);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.frameBufferTexture);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
if (g_bloom) {
|
|
|
|
glUseProgram(g_imageShader.compositeProgram);
|
|
|
|
glUniform1f(uniformAlpha, 0.5);
|
|
|
|
glBlendFunc(GL_ONE, GL_ONE);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.smallFrameBufferTexture[0]);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
glUseProgram(0);
|
|
|
|
|
|
|
|
checkGLErrors("image shader");
|
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static GLuint
|
2013-05-09 20:48:00 +00:00
|
|
|
bindProgram(Effect effect, OpenSubdiv::OsdDrawContext::PatchArray const & patch)
|
2012-12-11 01:15:13 +00:00
|
|
|
{
|
2013-05-09 20:48:00 +00:00
|
|
|
OpenSubdiv::OsdDrawContext::PatchDescriptor const & desc = patch.GetDescriptor();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
EffectDrawRegistry::ConfigType *
|
|
|
|
config = getInstance(effect, desc);
|
|
|
|
|
|
|
|
GLuint program = config->program;
|
|
|
|
|
|
|
|
glUseProgram(program);
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_transformUB == 0) {
|
2012-12-11 01:15:13 +00:00
|
|
|
glGenBuffers(1, &g_transformUB);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB);
|
|
|
|
glBufferData(GL_UNIFORM_BUFFER,
|
|
|
|
sizeof(transformData), NULL, GL_STATIC_DRAW);
|
|
|
|
};
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_transformUB);
|
|
|
|
glBufferSubData(GL_UNIFORM_BUFFER,
|
|
|
|
0, sizeof(transformData), &transformData);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
|
|
glBindBufferBase(GL_UNIFORM_BUFFER, g_transformBinding, g_transformUB);
|
|
|
|
|
|
|
|
// Update and bind tessellation state
|
|
|
|
struct Tessellation {
|
|
|
|
float TessLevel;
|
|
|
|
} tessellationData;
|
|
|
|
|
|
|
|
tessellationData.TessLevel = static_cast<float>(1 << g_tessLevel);
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_tessellationUB == 0) {
|
2012-12-11 01:15:13 +00:00
|
|
|
glGenBuffers(1, &g_tessellationUB);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_tessellationUB);
|
|
|
|
glBufferData(GL_UNIFORM_BUFFER,
|
|
|
|
sizeof(tessellationData), NULL, GL_STATIC_DRAW);
|
|
|
|
};
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_tessellationUB);
|
|
|
|
glBufferSubData(GL_UNIFORM_BUFFER,
|
|
|
|
0, sizeof(tessellationData), &tessellationData);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
|
|
glBindBufferBase(GL_UNIFORM_BUFFER, g_tessellationBinding, g_tessellationUB);
|
|
|
|
|
|
|
|
// Update and bind lighting state
|
|
|
|
struct Lighting {
|
|
|
|
struct Light {
|
|
|
|
float position[4];
|
|
|
|
float ambient[4];
|
|
|
|
float diffuse[4];
|
|
|
|
float specular[4];
|
|
|
|
} lightSource[2];
|
|
|
|
} lightingData = {
|
2013-03-16 01:03:22 +00:00
|
|
|
{{ { 0.6f, 1.0f, 0.6f, 0.0f },
|
2013-01-22 22:47:46 +00:00
|
|
|
{ 0.1f, 0.1f, 0.1f, 1.0f },
|
2013-03-16 01:03:22 +00:00
|
|
|
{ 1.7f, 1.3f, 1.1f, 1.0f },
|
|
|
|
{ 1.0f, 1.0f, 1.0f, 1.0f } },
|
2013-09-21 01:29:00 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
{ { -0.8f, 0.6f, -0.7f, 0.0f },
|
2013-01-22 22:47:46 +00:00
|
|
|
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
2013-03-16 01:03:22 +00:00
|
|
|
{ 0.8f, 0.8f, 1.5f, 1.0f },
|
|
|
|
{ 0.4f, 0.4f, 0.4f, 1.0f } }}
|
2012-12-11 01:15:13 +00:00
|
|
|
};
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_lightingUB == 0) {
|
2012-12-11 01:15:13 +00:00
|
|
|
glGenBuffers(1, &g_lightingUB);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB);
|
|
|
|
glBufferData(GL_UNIFORM_BUFFER,
|
|
|
|
sizeof(lightingData), NULL, GL_STATIC_DRAW);
|
|
|
|
};
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, g_lightingUB);
|
|
|
|
glBufferSubData(GL_UNIFORM_BUFFER,
|
|
|
|
0, sizeof(lightingData), &lightingData);
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
|
|
glBindBufferBase(GL_UNIFORM_BUFFER, g_lightingBinding, g_lightingUB);
|
|
|
|
|
|
|
|
//-----------------
|
|
|
|
int sampler = 7;
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// color ptex
|
|
|
|
GLint texData = glGetUniformLocation(program, "textureImage_Data");
|
|
|
|
GLint texPacking = glGetUniformLocation(program, "textureImage_Packing");
|
2013-09-21 01:29:00 +00:00
|
|
|
sampler = bindPTexture(program, g_osdPTexImage, texData, texPacking, sampler);
|
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) {
|
2012-12-11 01:15:13 +00:00
|
|
|
texData = glGetUniformLocation(program, "textureDisplace_Data");
|
|
|
|
texPacking = glGetUniformLocation(program, "textureDisplace_Packing");
|
2013-09-21 01:29:00 +00:00
|
|
|
sampler = bindPTexture(program, g_osdPTexDisplacement, texData, texPacking, sampler);
|
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) {
|
|
|
|
texData = glGetUniformLocation(program, "textureOcclusion_Data");
|
|
|
|
texPacking = glGetUniformLocation(program, "textureOcclusion_Packing");
|
2013-09-21 01:29:00 +00:00
|
|
|
sampler = bindPTexture(program, g_osdPTexOcclusion, texData, texPacking, sampler);
|
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) {
|
|
|
|
texData = glGetUniformLocation(program, "textureSpecular_Data");
|
|
|
|
texPacking = glGetUniformLocation(program, "textureSpecular_Packing");
|
2013-09-21 01:29:00 +00:00
|
|
|
sampler = bindPTexture(program, g_osdPTexSpecular, texData, texPacking, sampler);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
// other textures
|
|
|
|
if (g_ibl) {
|
|
|
|
if (g_diffuseEnvironmentMap) {
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_separate_shader_objects) || defined(GL_VERSION_4_1)
|
2012-12-11 01:15:13 +00:00
|
|
|
glProgramUniform1i(program, glGetUniformLocation(program, "diffuseEnvironmentMap"), 5);
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
|
|
|
glUniform1i(glGetUniformLocation(program, "diffuseEnvironmentMap"), 5);
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
glActiveTexture(GL_TEXTURE5);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_diffuseEnvironmentMap);
|
|
|
|
sampler++;
|
|
|
|
}
|
|
|
|
if (g_specularEnvironmentMap) {
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_separate_shader_objects) || defined(GL_VERSION_4_1)
|
2012-12-11 01:15:13 +00:00
|
|
|
glProgramUniform1i(program, glGetUniformLocation(program, "specularEnvironmentMap"), 6);
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
|
|
|
glUniform1i(glGetUniformLocation(program, "specularEnvironmentMap"), 6);
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
glActiveTexture(GL_TEXTURE6);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_specularEnvironmentMap);
|
|
|
|
sampler++;
|
|
|
|
}
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return program;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2013-09-21 01:29:00 +00:00
|
|
|
drawModel()
|
|
|
|
{
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
2012-12-11 01:15:13 +00:00
|
|
|
GLuint bVertex = g_mesh->BindVertexBuffer();
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
|
|
|
g_mesh->BindVertexBuffer();
|
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
OpenSubdiv::OsdDrawContext::PatchArrayVector const & patches =
|
|
|
|
g_mesh->GetDrawContext()->patchArrays;
|
2013-01-29 23:54:18 +00:00
|
|
|
glBindVertexArray(g_vao);
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
// patch drawing
|
2013-09-21 01:29:00 +00:00
|
|
|
for (int i = 0; i < (int)patches.size(); ++i) {
|
2013-05-09 20:48:00 +00:00
|
|
|
OpenSubdiv::OsdDrawContext::PatchArray const & patch = patches[i];
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-09 20:48:00 +00:00
|
|
|
OpenSubdiv::OsdDrawContext::PatchDescriptor desc = patch.GetDescriptor();
|
|
|
|
OpenSubdiv::FarPatchTables::Type patchType = desc.GetType();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-05-17 00:10:17 +00:00
|
|
|
GLenum primType;
|
2013-09-21 01:29:00 +00:00
|
|
|
switch (patchType) {
|
2013-05-17 00:10:17 +00:00
|
|
|
case OpenSubdiv::FarPatchTables::QUADS:
|
|
|
|
primType = GL_LINES_ADJACENCY;
|
|
|
|
break;
|
|
|
|
case OpenSubdiv::FarPatchTables::TRIANGLES:
|
|
|
|
primType = GL_TRIANGLES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
2012-12-11 01:15:13 +00:00
|
|
|
primType = GL_PATCHES;
|
2013-05-09 20:48:00 +00:00
|
|
|
glPatchParameteri(GL_PATCH_VERTICES, desc.GetNumControlVertices());
|
2013-05-17 00:10:17 +00:00
|
|
|
#else
|
|
|
|
primType = GL_POINTS;
|
|
|
|
#endif
|
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
|
2013-07-18 19:57:26 +00:00
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
2013-06-01 00:11:16 +00:00
|
|
|
if (g_mesh->GetDrawContext()->GetVertexTextureBuffer()) {
|
2013-05-17 00:10:17 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2013-06-01 00:11:16 +00:00
|
|
|
glBindTexture(GL_TEXTURE_BUFFER,
|
|
|
|
g_mesh->GetDrawContext()->GetVertexTextureBuffer());
|
2013-05-17 00:10:17 +00:00
|
|
|
glTexBuffer(GL_TEXTURE_BUFFER, GL_R32F, bVertex);
|
|
|
|
}
|
2013-06-01 00:11:16 +00:00
|
|
|
if (g_mesh->GetDrawContext()->GetVertexValenceTextureBuffer()) {
|
2013-05-17 00:10:17 +00:00
|
|
|
glActiveTexture(GL_TEXTURE1);
|
2013-06-01 00:11:16 +00:00
|
|
|
glBindTexture(GL_TEXTURE_BUFFER,
|
|
|
|
g_mesh->GetDrawContext()->GetVertexValenceTextureBuffer());
|
2013-05-17 00:10:17 +00:00
|
|
|
}
|
2013-06-01 00:11:16 +00:00
|
|
|
if (g_mesh->GetDrawContext()->GetQuadOffsetsTextureBuffer()) {
|
2013-05-17 00:10:17 +00:00
|
|
|
glActiveTexture(GL_TEXTURE2);
|
2013-06-01 00:11:16 +00:00
|
|
|
glBindTexture(GL_TEXTURE_BUFFER,
|
|
|
|
g_mesh->GetDrawContext()->GetQuadOffsetsTextureBuffer());
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2013-07-18 19:57:26 +00:00
|
|
|
#endif
|
2013-06-01 00:11:16 +00:00
|
|
|
if (g_mesh->GetDrawContext()->GetPatchParamTextureBuffer()) {
|
2013-05-17 00:10:17 +00:00
|
|
|
glActiveTexture(GL_TEXTURE3);
|
2013-01-29 23:54:18 +00:00
|
|
|
glBindTexture(GL_TEXTURE_BUFFER,
|
2013-06-01 00:11:16 +00:00
|
|
|
g_mesh->GetDrawContext()->GetPatchParamTextureBuffer());
|
2013-01-29 23:54:18 +00:00
|
|
|
}
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
GLuint program = bindProgram(effect, patch);
|
|
|
|
|
|
|
|
GLint nonAdaptiveLevel = glGetUniformLocation(program, "nonAdaptiveLevel");
|
|
|
|
if (nonAdaptiveLevel != -1) {
|
2013-01-29 23:54:18 +00:00
|
|
|
#if defined(GL_ARB_separate_shader_objects) || defined(GL_VERSION_4_1)
|
2012-12-11 01:15:13 +00:00
|
|
|
glProgramUniform1i(program, nonAdaptiveLevel, g_level);
|
2013-01-29 23:54:18 +00:00
|
|
|
#else
|
|
|
|
glUniform1i(nonAdaptiveLevel, g_level);
|
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
GLint displacementScale = glGetUniformLocation(program, "displacementScale");
|
|
|
|
if (displacementScale != -1)
|
|
|
|
glUniform1f(displacementScale, g_displacementScale);
|
2013-09-21 01:29:00 +00:00
|
|
|
|
|
|
|
GLint mipmapBias = glGetUniformLocation(program, "mipmapBias");
|
|
|
|
if (mipmapBias != -1)
|
|
|
|
glUniform1f(mipmapBias, g_mipmapBias);
|
2013-01-29 23:54:18 +00:00
|
|
|
|
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
2012-12-11 01:15:13 +00:00
|
|
|
GLuint overrideColor = glGetUniformLocation(program, "overrideColor");
|
2013-05-09 20:48:00 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
float const * color = getAdaptivePatchColor(desc);
|
2013-05-22 23:26:02 +00:00
|
|
|
glProgramUniform4f(program, overrideColor, color[0], color[1], color[2], color[3]);
|
2013-01-29 23:54:18 +00:00
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_wire == DISPLAY_WIRE) {
|
2012-12-11 01:15:13 +00:00
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
}
|
2013-03-08 01:50:15 +00:00
|
|
|
|
2013-07-18 19:57:26 +00:00
|
|
|
GLuint uniformGregoryQuadOffsetBase =
|
2013-09-21 01:29:00 +00:00
|
|
|
glGetUniformLocation(program, "OsdGregoryQuadOffsetBase");
|
2013-07-18 19:57:26 +00:00
|
|
|
GLuint uniformPrimitiveIdBase =
|
2013-09-21 01:29:00 +00:00
|
|
|
glGetUniformLocation(program, "OsdPrimitiveIdBase");
|
2013-03-08 01:50:15 +00:00
|
|
|
|
2013-07-18 19:57:26 +00:00
|
|
|
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
|
|
|
glProgramUniform1i(program, uniformGregoryQuadOffsetBase,
|
2013-09-21 01:29:00 +00:00
|
|
|
patch.GetQuadOffsetIndex());
|
2013-07-18 19:57:26 +00:00
|
|
|
glProgramUniform1i(program, uniformPrimitiveIdBase,
|
2013-09-21 01:29:00 +00:00
|
|
|
patch.GetPatchIndex());
|
2013-07-18 19:57:26 +00:00
|
|
|
#else
|
|
|
|
glUniform1i(uniformGregoryQuadOffsetBase,
|
2013-09-21 01:29:00 +00:00
|
|
|
patch.GetQuadOffsetIndex());
|
2013-07-18 19:57:26 +00:00
|
|
|
glUniform1i(uniformPrimitiveIdBase,
|
2013-09-21 01:29:00 +00:00
|
|
|
patch.GetPatchIndex());
|
2013-07-18 19:57:26 +00:00
|
|
|
#endif
|
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)));
|
2013-09-21 01:29:00 +00:00
|
|
|
if (g_wire == DISPLAY_WIRE) {
|
2012-12-11 01:15:13 +00:00
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
}
|
|
|
|
}
|
2013-01-29 23:54:18 +00:00
|
|
|
glBindVertexArray(0);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-21 01:29:00 +00:00
|
|
|
drawSky()
|
|
|
|
{
|
2012-12-11 01:15:13 +00:00
|
|
|
glUseProgram(g_sky.program);
|
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-09-21 01:29:00 +00:00
|
|
|
}
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
void
|
2013-09-21 01:29:00 +00:00
|
|
|
display()
|
|
|
|
{
|
2013-03-16 01:03:22 +00:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, g_imageShader.frameBuffer);
|
|
|
|
|
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
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
// primitive counting
|
|
|
|
glBeginQuery(GL_PRIMITIVES_GENERATED, g_primQuery);
|
|
|
|
|
|
|
|
double aspect = g_width/(double)g_height;
|
|
|
|
identity(transformData.ModelViewMatrix);
|
|
|
|
translate(transformData.ModelViewMatrix, -g_pan[0], -g_pan[1], -g_dolly);
|
|
|
|
rotate(transformData.ModelViewMatrix, g_rotate[1], 1, 0, 0);
|
|
|
|
rotate(transformData.ModelViewMatrix, g_rotate[0], 0, 1, 0);
|
2013-03-16 01:03:22 +00:00
|
|
|
if (g_yup)
|
|
|
|
rotate(transformData.ModelViewMatrix, -90, 1, 0, 0);
|
2013-01-29 23:54:18 +00:00
|
|
|
translate(transformData.ModelViewMatrix, -g_center[0], -g_center[1], -g_center[2]);
|
|
|
|
perspective(transformData.ProjectionMatrix, 45.0f, (float)aspect, g_size*0.001f,
|
|
|
|
g_size+g_dolly);
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
multMatrix(transformData.ModelViewProjectionMatrix,
|
|
|
|
transformData.ModelViewMatrix,
|
|
|
|
transformData.ProjectionMatrix);
|
|
|
|
inverseMatrix(transformData.ModelViewInverseMatrix,
|
|
|
|
transformData.ModelViewMatrix);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-18 18:56:09 +00:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
drawModel();
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-18 18:56:09 +00:00
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glUseProgram(0);
|
|
|
|
|
|
|
|
glEndQuery(GL_PRIMITIVES_GENERATED);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
applyImageShader();
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
s.Stop();
|
|
|
|
float drawCpuTime = float(s.GetElapsed() * 1000.0f);
|
|
|
|
s.Start();
|
2012-08-04 02:51:27 +00:00
|
|
|
glFinish();
|
2012-12-11 01:15:13 +00:00
|
|
|
s.Stop();
|
|
|
|
float drawGpuTime = float(s.GetElapsed() * 1000.0f);
|
|
|
|
|
|
|
|
GLuint numPrimsGenerated = 0;
|
|
|
|
glGetQueryObjectuiv(g_primQuery, GL_QUERY_RESULT, &numPrimsGenerated);
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
|
|
|
mouse(GLFWwindow *, int button, int state, int mods)
|
2013-01-31 23:34:35 +00:00
|
|
|
#else
|
2013-09-21 01:29:00 +00:00
|
|
|
mouse(int button, int state)
|
2013-01-31 23:34:35 +00:00
|
|
|
#endif
|
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
|
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
|
|
|
motion(GLFWwindow *, double dx, double dy)
|
|
|
|
{
|
|
|
|
int x = (int)dx, y = (int)dy;
|
2013-01-31 23:34:35 +00:00
|
|
|
#else
|
2013-09-21 01:29:00 +00:00
|
|
|
motion(int x, int y)
|
|
|
|
{
|
2013-09-24 16:04:20 +00:00
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-09-21 01:29:00 +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
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
glDeleteQueries(1, &g_primQuery);
|
2013-01-29 23:54:18 +00:00
|
|
|
glDeleteVertexArrays(1, &g_vao);
|
|
|
|
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-02-20 01:33:32 +00:00
|
|
|
delete g_cpuComputeController;
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENMP
|
|
|
|
delete g_ompComputeController;
|
2012-08-04 02:51:27 +00:00
|
|
|
#endif
|
2012-12-11 01:15:13 +00:00
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2013-02-20 01:33:32 +00:00
|
|
|
delete g_clComputeController;
|
2012-12-11 01:15:13 +00:00
|
|
|
uninitCL(g_clContext, g_clQueue);
|
|
|
|
#endif
|
|
|
|
|
2013-02-20 01:33:32 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_CUDA
|
|
|
|
delete g_cudaComputeController;
|
|
|
|
cudaDeviceReset();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
|
|
|
|
delete g_glslTransformFeedbackComputeController;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_COMPUTE
|
|
|
|
delete g_glslComputeController;
|
|
|
|
#endif
|
|
|
|
|
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.program) glDeleteProgram(g_sky.program);
|
|
|
|
if (g_sky.vertexBuffer) glDeleteBuffers(1, &g_sky.vertexBuffer);
|
|
|
|
if (g_sky.elementBuffer) glDeleteBuffers(1, &g_sky.elementBuffer);
|
2013-03-16 01:03:22 +00:00
|
|
|
|
|
|
|
glDeleteFramebuffers(1, &g_imageShader.frameBuffer);
|
|
|
|
glDeleteTextures(1, &g_imageShader.frameBufferTexture);
|
|
|
|
glDeleteTextures(1, &g_imageShader.frameBufferDepthTexture);
|
|
|
|
|
|
|
|
glDeleteFramebuffers(2, g_imageShader.smallFrameBuffer);
|
|
|
|
glDeleteTextures(2, g_imageShader.smallFrameBufferTexture);
|
|
|
|
|
|
|
|
glDeleteProgram(g_imageShader.blurProgram);
|
|
|
|
glDeleteProgram(g_imageShader.hipassProgram);
|
|
|
|
glDeleteProgram(g_imageShader.compositeProgram);
|
|
|
|
|
|
|
|
glDeleteVertexArrays(1, &g_imageShader.vao);
|
|
|
|
glDeleteBuffers(1, &g_imageShader.vbo);
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2012-12-11 01:15:13 +00:00
|
|
|
static void
|
|
|
|
callbackWireframe(int b)
|
|
|
|
{
|
|
|
|
g_wire = b;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
callbackKernel(int k)
|
|
|
|
{
|
2012-08-04 02:51:27 +00:00
|
|
|
g_kernel = k;
|
|
|
|
createOsdMesh(g_level, g_kernel);
|
2013-09-21 01:29:00 +00:00
|
|
|
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
|
|
|
if (g_kernel == kCL and g_clContext == NULL) {
|
|
|
|
// Initialize OpenCL
|
|
|
|
if (initCL(&g_clContext, &g_clQueue) == false) {
|
|
|
|
printf("Error in initializing OpenCL\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
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
|
|
|
|
callbackScheme(int s)
|
|
|
|
{
|
|
|
|
g_scheme = s;
|
|
|
|
createOsdMesh(g_level, g_kernel);
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
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
|
2013-09-21 01:29:00 +00:00
|
|
|
callbackColor(int c)
|
|
|
|
{
|
|
|
|
g_color = c;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
callbackDisplacement(int d)
|
|
|
|
{
|
|
|
|
g_displacement = d;
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
callbackNormal(int n)
|
|
|
|
{
|
|
|
|
g_normal = n;
|
|
|
|
}
|
|
|
|
static void
|
2012-12-11 01:15:13 +00:00
|
|
|
callbackCheckBox(bool checked, int button)
|
|
|
|
{
|
|
|
|
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:
|
2013-02-05 23:25:46 +00:00
|
|
|
if (OpenSubdiv::OsdGLDrawContext::SupportsAdaptiveTessellation()) {
|
|
|
|
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;
|
|
|
|
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-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
|
|
|
|
callbackSlider(float value, int data)
|
|
|
|
{
|
|
|
|
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
|
2013-09-21 01:29:00 +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();
|
|
|
|
|
|
|
|
effectRegistry.Reset();
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2013-09-21 01:29:00 +00:00
|
|
|
static void
|
|
|
|
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
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
|
|
|
keyboard(GLFWwindow *, int key, int scancode, int event, int mods)
|
2013-01-31 23:34:35 +00:00
|
|
|
#else
|
2013-06-20 18:53:33 +00:00
|
|
|
#define GLFW_KEY_ESCAPE GLFW_KEY_ESC
|
2013-09-21 01:29:00 +00:00
|
|
|
keyboard(int key, int event)
|
2013-01-31 23:34:35 +00:00
|
|
|
#endif
|
2013-09-21 01:29:00 +00:00
|
|
|
{
|
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;
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void
|
2013-09-21 01:29:00 +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
|
2013-09-21 01:29:00 +00:00
|
|
|
initGL()
|
|
|
|
{
|
2012-08-04 02:51:27 +00:00
|
|
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
|
|
|
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
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
glGenQueries(1, &g_primQuery);
|
|
|
|
glGenVertexArrays(1, &g_vao);
|
|
|
|
glGenVertexArrays(1, &g_skyVAO);
|
2013-03-16 01:03:22 +00:00
|
|
|
|
|
|
|
glGenFramebuffers(1, &g_imageShader.frameBuffer);
|
|
|
|
glGenTextures(1, &g_imageShader.frameBufferTexture);
|
|
|
|
glGenTextures(1, &g_imageShader.frameBufferDepthTexture);
|
|
|
|
|
|
|
|
glGenFramebuffers(2, g_imageShader.smallFrameBuffer);
|
|
|
|
glGenTextures(2, g_imageShader.smallFrameBufferTexture);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.frameBufferTexture);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.frameBufferDepthTexture);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, g_imageShader.smallFrameBufferTexture[i]);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
}
|
2013-09-21 01:29:00 +00:00
|
|
|
|
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
|
|
|
//------------------------------------------------------------------------------
|
2013-09-21 01:29:00 +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-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
|
|
|
|
callbackError(OpenSubdiv::OsdErrorType err, const char *message)
|
|
|
|
{
|
|
|
|
printf("OsdError: %d\n", err);
|
|
|
|
printf("%s", message);
|
|
|
|
}
|
2013-01-31 23:34:35 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
static void
|
|
|
|
setGLCoreProfile()
|
|
|
|
{
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
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
|
|
|
|
#endif
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 2 and GLFW_VERSION_MINOR >= 7
|
2013-01-31 23:34:35 +00:00
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
#if not defined(__APPLE__)
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 4);
|
|
|
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
|
|
|
|
#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
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
//------------------------------------------------------------------------------
|
2013-09-21 01:29:00 +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-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-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]);
|
2012-12-11 01:15:13 +00:00
|
|
|
else if (colorFilename == NULL)
|
|
|
|
colorFilename = argv[i];
|
|
|
|
else if (displacementFilename == NULL) {
|
|
|
|
displacementFilename = argv[i];
|
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];
|
|
|
|
g_occlusion = 1;
|
|
|
|
} else if (specularFilename == NULL) {
|
|
|
|
specularFilename = argv[i];
|
|
|
|
g_specular = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 23:54:18 +00:00
|
|
|
OsdSetErrorCallback(callbackError);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-03-16 01:03:22 +00:00
|
|
|
static const char windowTitle[] = "OpenSubdiv ptexViewer";
|
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-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
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);
|
|
|
|
#else
|
2013-01-29 23:54:18 +00:00
|
|
|
if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8,
|
|
|
|
fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) {
|
2013-01-31 23:34:35 +00:00
|
|
|
printf("Failed to open window.\n");
|
2013-01-29 23:54:18 +00:00
|
|
|
glfwTerminate();
|
|
|
|
return 1;
|
|
|
|
}
|
2013-01-31 23:34:35 +00:00
|
|
|
glfwSetWindowTitle(windowTitle);
|
|
|
|
glfwSetKeyCallback(keyboard);
|
|
|
|
glfwSetMousePosCallback(motion);
|
|
|
|
glfwSetMouseButtonCallback(mouse);
|
|
|
|
#endif
|
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();
|
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
2013-03-16 01:03:22 +00:00
|
|
|
glfwSetWindowSizeCallback(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
|
|
|
#else
|
|
|
|
glfwSetWindowSizeCallback(reshape);
|
2013-03-19 21:31:44 +00:00
|
|
|
glfwSetWindowCloseCallback(windowClose);
|
2013-03-16 01:03:22 +00:00
|
|
|
#endif
|
|
|
|
|
2013-02-05 23:25:46 +00:00
|
|
|
// activate feature adaptive tessellation if OSD supports it
|
|
|
|
g_adaptive = OpenSubdiv::OsdGLDrawContext::SupportsAdaptiveTessellation();
|
|
|
|
|
2012-08-04 02:51:27 +00:00
|
|
|
#if OPENSUBDIV_HAS_CUDA
|
|
|
|
// Note: This function randomly crashes with linux 5.0-dev driver.
|
|
|
|
// cudaGetDeviceProperties overrun stack..?
|
2013-09-21 01:29:00 +00:00
|
|
|
cudaGLSetGLDevice(cutGetMaxGflopsDeviceId());
|
2012-08-04 02:51:27 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
g_hud.Init(g_width, g_height);
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_KERNEL, "CPU (K)", true,
|
|
|
|
10, 10, callbackKernel, kCPU, 'k');
|
2012-12-11 01:15:13 +00:00
|
|
|
#ifdef OPENSUBDIV_HAS_OPENMP
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_KERNEL, "OPENMP", false,
|
|
|
|
10, 30, callbackKernel, kOPENMP, 'k');
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_CUDA
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_KERNEL, "CUDA", false,
|
|
|
|
10, 50, callbackKernel, kCUDA, 'k');
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_OPENCL
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_KERNEL, "OPENCL", false,
|
|
|
|
10, 70, callbackKernel, kCL, 'k');
|
2012-12-11 01:15:13 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSUBDIV_HAS_GLSL_TRANSFORM_FEEDBACK
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_KERNEL, "GLSL Transform Feedback", false,
|
|
|
|
10, 90, callbackKernel, kGLSL, 'k');
|
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) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddRadioButton(HUD_RB_KERNEL, "GLSL Compute", false,
|
|
|
|
10, 110, callbackKernel, kGLSLCompute, 'k');
|
2012-12-11 01:15:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
if (OpenSubdiv::OsdGLDrawContext::SupportsAdaptiveTessellation())
|
|
|
|
g_hud.AddCheckBox("Adaptive (`)", g_adaptive,
|
|
|
|
10, 150, callbackCheckBox, HUD_CB_ADAPTIVE, '`');
|
|
|
|
|
|
|
|
g_hud.AddRadioButton(HUD_RB_SCHEME, "CATMARK", true, 10, 190, callbackScheme, 0);
|
|
|
|
g_hud.AddRadioButton(HUD_RB_SCHEME, "BILINEAR", false, 10, 210, callbackScheme, 1);
|
|
|
|
|
|
|
|
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, 220+i*20, callbackLevel, i, '0'+i);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hud.AddRadioButton(HUD_RB_WIRE, "Wire (W)", (g_wire == DISPLAY_WIRE),
|
|
|
|
100, 10, callbackWireframe, 0, 'w');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_WIRE, "Shaded", (g_wire == DISPLAY_SHADED),
|
|
|
|
100, 30, callbackWireframe, 1, 'w');
|
|
|
|
g_hud.AddRadioButton(HUD_RB_WIRE, "Wire on Shaded", (g_wire == DISPLAY_WIRE_ON_SHADED),
|
|
|
|
100, 50, callbackWireframe, 2, 'w');
|
|
|
|
|
|
|
|
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);
|
|
|
|
g_hud.AddSlider("Displacementd", 0, 5, 1,
|
|
|
|
-200, 490, 20, false, callbackSlider, 1);
|
|
|
|
|
|
|
|
if (occlusionFilename != NULL) {
|
|
|
|
g_hud.AddCheckBox("Ambient Occlusion (A)", g_occlusion,
|
|
|
|
250, 10, callbackCheckBox, HUD_CB_DISPLAY_OCCLUSION, 'a');
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
2012-12-11 01:15:13 +00:00
|
|
|
if (specularFilename != NULL)
|
|
|
|
g_hud.AddCheckBox("Specular (S)", g_specular,
|
2013-09-21 01:29:00 +00:00
|
|
|
250, 30, callbackCheckBox, HUD_CB_DISPLAY_SPECULAR, 's');
|
2012-08-04 02:51:27 +00:00
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
if (diffuseEnvironmentMap || specularEnvironmentMap) {
|
2013-09-21 01:29:00 +00:00
|
|
|
g_hud.AddCheckBox("IBL (I)", g_ibl,
|
|
|
|
250, 50, callbackCheckBox, HUD_CB_IBL, 'i');
|
2012-08-04 02:51:27 +00:00
|
|
|
}
|
|
|
|
|
2012-12-11 01:15:13 +00:00
|
|
|
g_hud.AddCheckBox("Animate vertices (M)", g_moveScale != 0.0,
|
|
|
|
450, 10, callbackCheckBox, HUD_CB_ANIMATE_VERTICES, 'm');
|
|
|
|
g_hud.AddCheckBox("Screen space LOD (V)", g_screenSpaceTess,
|
2013-09-21 01:29:00 +00:00
|
|
|
450, 30, callbackCheckBox, HUD_CB_VIEW_LOD, 'v');
|
2013-06-27 20:34:25 +00:00
|
|
|
g_hud.AddCheckBox("Fractional spacing (T)", g_fractionalSpacing,
|
2013-09-21 01:29:00 +00:00
|
|
|
450, 50, callbackCheckBox, HUD_CB_FRACTIONAL_SPACING, 't');
|
2012-12-11 01:15:13 +00:00
|
|
|
g_hud.AddCheckBox("Frustum Patch Culling (B)", g_patchCull,
|
2013-09-21 01:29:00 +00:00
|
|
|
450, 70, callbackCheckBox, HUD_CB_PATCH_CULL, 'b');
|
2013-06-27 20:34:25 +00:00
|
|
|
g_hud.AddCheckBox("Bloom (Y)", g_bloom,
|
2013-09-21 01:29:00 +00:00
|
|
|
450, 90, callbackCheckBox, HUD_CB_BLOOM, 'y');
|
2013-07-18 22:06:48 +00:00
|
|
|
g_hud.AddCheckBox("Freeze (spc)", g_freeze,
|
2013-09-21 01:29:00 +00:00
|
|
|
450, 110, callbackCheckBox, HUD_CB_FREEZE, ' ');
|
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)
|
|
|
|
g_osdPTexImage = createPtex(colorFilename);
|
|
|
|
if (displacementFilename)
|
|
|
|
g_osdPTexDisplacement = createPtex(displacementFilename);
|
|
|
|
if (occlusionFilename)
|
|
|
|
g_osdPTexOcclusion = createPtex(occlusionFilename);
|
|
|
|
if (specularFilename)
|
|
|
|
g_osdPTexSpecular = createPtex(specularFilename);
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
shape *shape = shape::parseShape(str.c_str());
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2013-03-16 01:03:22 +00:00
|
|
|
createImageShader();
|
2012-12-11 01:15:13 +00:00
|
|
|
|
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
|
|
|
|
2013-09-21 01:29:00 +00:00
|
|
|
#if GLFW_VERSION_MAJOR >= 3
|
2013-01-31 23:34:35 +00:00
|
|
|
glfwPollEvents();
|
|
|
|
glfwSwapBuffers(g_window);
|
|
|
|
#else
|
|
|
|
glfwSwapBuffers();
|
|
|
|
#endif
|
|
|
|
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
|
|
|
}
|