Skip to content

Commit e1789d7

Browse files
committed
apply clang-format.
1 parent 72dfcfb commit e1789d7

File tree

2 files changed

+123
-56
lines changed

2 files changed

+123
-56
lines changed

examples/openglviewer/main.cc

+102-56
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
#include "external/linalg.h"
4242
#include "io-util.hh"
4343
#include "linear-algebra.hh"
44+
#include "pprinter.hh" // import to_string(tinyusdz::value::***)
4445
#include "tinyusdz.hh"
4546
#include "tydra/render-data.hh"
4647
#include "tydra/scene-access.hh"
4748
#include "value-pprint.hh" // import to_string(tinyusdz::value::***)
48-
#include "pprinter.hh" // import to_string(tinyusdz::value::***)
4949

5050
// local
5151
#include "shader.hh"
@@ -105,13 +105,13 @@ struct GLTexState {
105105
GLTexParams texParams;
106106
std::string sampler_name;
107107
uint32_t slot_id{0};
108-
GLuint tex_id; // glBindTexture id
108+
GLuint tex_id; // glBindTexture id
109109
GLint u_tex{-1}; // sampler glUniform location
110110

111-
GLint u_transform; // texcoord transform
111+
GLint u_transform; // texcoord transform
112112
};
113113

114-
template<typename T>
114+
template <typename T>
115115
struct GLTexOrFactor {
116116
GLTexOrFactor(const T &v) : factor(v) {}
117117

@@ -120,7 +120,7 @@ struct GLTexOrFactor {
120120
GLint u_factor{-1};
121121
};
122122

123-
template<typename T>
123+
template <typename T>
124124
struct GLUniformFactor {
125125
GLUniformFactor(const T &v) : factor(v) {}
126126

@@ -129,7 +129,6 @@ struct GLUniformFactor {
129129
};
130130

131131
struct GLUsdPreviewSurfaceState {
132-
133132
static constexpr auto kDiffuseColor = "diffuseColor";
134133
static constexpr auto kEmissiveColor = "emissiveColor";
135134
static constexpr auto kSpecularColor = "specularColor";
@@ -147,10 +146,11 @@ struct GLUsdPreviewSurfaceState {
147146
GLTexOrFactor<tinyusdz::tydra::vec3> diffuseColor{{0.18f, 0.18f, 0.18f}};
148147
GLTexOrFactor<tinyusdz::tydra::vec3> emissiveColor{{0.0f, 0.0f, 0.0f}};
149148

150-
GLUniformFactor<int> useSpecularWorkflow{0}; // non-texturable
149+
GLUniformFactor<int> useSpecularWorkflow{0}; // non-texturable
151150

152-
GLTexOrFactor<tinyusdz::tydra::vec3> specularColor{{0.0f, 0.0f, 0.0f}}; // useSpecularWorkflow = 1
153-
GLTexOrFactor<float> metallic{0.0f}; // useSpecularWorkflow = 0
151+
GLTexOrFactor<tinyusdz::tydra::vec3> specularColor{
152+
{0.0f, 0.0f, 0.0f}}; // useSpecularWorkflow = 1
153+
GLTexOrFactor<float> metallic{0.0f}; // useSpecularWorkflow = 0
154154

155155
GLTexOrFactor<float> roughness{0.5f};
156156
GLTexOrFactor<float> clearcoat{0.0f};
@@ -160,24 +160,22 @@ struct GLUsdPreviewSurfaceState {
160160

161161
GLTexOrFactor<float> ior{1.5f};
162162

163-
GLTexOrFactor<tinyusdz::tydra::vec3> normal{{0.0f, 0.0f, 1.0f}}; // normal map
163+
GLTexOrFactor<tinyusdz::tydra::vec3> normal{
164+
{0.0f, 0.0f, 1.0f}}; // normal map
164165

165166
// No displacement mapping on OpenGL
166-
//GLTexOrFactor<float> displacement{0.0f};
167-
168-
GLTexOrFactor<float> occlusion{1.0f};
167+
// GLTexOrFactor<float> displacement{0.0f};
169168

169+
GLTexOrFactor<float> occlusion{1.0f};
170170
};
171171

172-
template<typename T>
173-
bool SetupGLUsdPreviewSurfaceParam(
174-
const GLuint prog_id,
175-
const tinyusdz::tydra::RenderScene &scene,
176-
const std::string &base_shadername,
177-
const tinyusdz::tydra::ShaderParam<T> &s,
172+
template <typename T>
173+
bool SetupGLUsdPreviewSurfaceParam(const GLuint prog_id,
174+
const tinyusdz::tydra::RenderScene &scene,
175+
const std::string &base_shadername,
176+
const tinyusdz::tydra::ShaderParam<T> &s,
178177

179-
GLTexOrFactor<T> &dst)
180-
{
178+
GLTexOrFactor<T> &dst) {
181179
if (s.is_texture()) {
182180
{
183181
std::string u_name = base_shadername + "Tex";
@@ -192,7 +190,8 @@ bool SetupGLUsdPreviewSurfaceParam(
192190
if (s.textureId < 0 || s.textureId >= scene.textures.size()) {
193191
std::cerr << "Invalid txtureId for " << base_shadername + "\n";
194192
} else {
195-
const tinyusdz::tydra::UVTexture &uvtex = scene.textures[size_t(s.textureId)];
193+
const tinyusdz::tydra::UVTexture &uvtex =
194+
scene.textures[size_t(s.textureId)];
196195
dst.tex.texParams.uv_transform = uvtex.transform;
197196
}
198197
}
@@ -209,102 +208,130 @@ bool SetupGLUsdPreviewSurfaceParam(
209208
return true;
210209
}
211210

212-
bool ReloadShader(
213-
GLuint prog_id, const std::string &vert_filepath, const std::string &frag_filepath) {
211+
bool ReloadShader(GLuint prog_id, const std::string &vert_filepath,
212+
const std::string &frag_filepath) {
214213
std::string vert_str;
215214
std::string frag_str;
216215

217216
if (vert_filepath.size() && tinyusdz::io::FileExists(vert_filepath)) {
218-
219217
std::vector<uint8_t> bytes;
220218
std::string err;
221219
if (!tinyusdz::io::ReadWholeFile(&bytes, &err, vert_filepath)) {
222220
std::cerr << "Read vertg shader failed: " << err << "\n";
223221
return false;
224222
}
225223

226-
vert_str = std::string(reinterpret_cast<char *>(bytes.data()), bytes.size());
224+
vert_str =
225+
std::string(reinterpret_cast<char *>(bytes.data()), bytes.size());
226+
227+
std::cout << "VERT:\n" << vert_str << "\n";
227228
}
228229

229230
if (frag_filepath.size() && tinyusdz::io::FileExists(frag_filepath)) {
230-
231231
std::vector<uint8_t> bytes;
232232
std::string err;
233233
if (!tinyusdz::io::ReadWholeFile(&bytes, &err, frag_filepath)) {
234234
std::cerr << "Read frag shader failed: " << err << "\n";
235235
return false;
236236
}
237237

238-
frag_str = std::string(reinterpret_cast<char *>(bytes.data()), bytes.size());
238+
frag_str =
239+
std::string(reinterpret_cast<char *>(bytes.data()), bytes.size());
240+
241+
std::cout << "FRAG:\n" << frag_str << "\n";
239242
}
240243

241244
// TODO
242245
return true;
243246
}
244247

245-
246-
bool SetupGLUsdPreviewSurface(
247-
GLuint prog_id,
248-
tinyusdz::tydra::RenderScene &scene,
249-
tinyusdz::tydra::RenderMaterial &m,
250-
GLUsdPreviewSurfaceState &dst)
251-
{
248+
bool SetupGLUsdPreviewSurface(GLuint prog_id,
249+
tinyusdz::tydra::RenderScene &scene,
250+
tinyusdz::tydra::RenderMaterial &m,
251+
GLUsdPreviewSurfaceState &dst) {
252252
const auto surfaceShader = m.surfaceShader;
253253

254-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kDiffuseColor, surfaceShader.diffuseColor, dst.diffuseColor)) {
254+
if (!SetupGLUsdPreviewSurfaceParam(
255+
prog_id, scene, GLUsdPreviewSurfaceState::kDiffuseColor,
256+
surfaceShader.diffuseColor, dst.diffuseColor)) {
255257
return false;
256258
}
257259

258-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kEmissiveColor, surfaceShader.emissiveColor, dst.emissiveColor)) {
260+
if (!SetupGLUsdPreviewSurfaceParam(
261+
prog_id, scene, GLUsdPreviewSurfaceState::kEmissiveColor,
262+
surfaceShader.emissiveColor, dst.emissiveColor)) {
259263
return false;
260264
}
261265

262-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kSpecularColor, surfaceShader.specularColor, dst.specularColor)) {
266+
if (!SetupGLUsdPreviewSurfaceParam(
267+
prog_id, scene, GLUsdPreviewSurfaceState::kSpecularColor,
268+
surfaceShader.specularColor, dst.specularColor)) {
263269
return false;
264270
}
265271

266-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kMetallic, surfaceShader.metallic, dst.metallic)) {
272+
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene,
273+
GLUsdPreviewSurfaceState::kMetallic,
274+
surfaceShader.metallic, dst.metallic)) {
267275
return false;
268276
}
269277

270-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kRoughness, surfaceShader.roughness, dst.roughness)) {
278+
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene,
279+
GLUsdPreviewSurfaceState::kRoughness,
280+
surfaceShader.roughness, dst.roughness)) {
271281
return false;
272282
}
273283

274-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kClearcoat, surfaceShader.clearcoat, dst.clearcoat)) {
284+
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene,
285+
GLUsdPreviewSurfaceState::kClearcoat,
286+
surfaceShader.clearcoat, dst.clearcoat)) {
275287
return false;
276288
}
277289

278-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kClearcoatRoughness, surfaceShader.clearcoatRoughness, dst.clearcoatRoughness)) {
290+
if (!SetupGLUsdPreviewSurfaceParam(
291+
prog_id, scene, GLUsdPreviewSurfaceState::kClearcoatRoughness,
292+
surfaceShader.clearcoatRoughness, dst.clearcoatRoughness)) {
279293
return false;
280294
}
281295

282-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kOpacity, surfaceShader.opacity, dst.opacity)) {
296+
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene,
297+
GLUsdPreviewSurfaceState::kOpacity,
298+
surfaceShader.opacity, dst.opacity)) {
283299
return false;
284300
}
285301

286-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kOpacityThreshold, surfaceShader.opacityThreshold, dst.opacityThreshold)) {
302+
if (!SetupGLUsdPreviewSurfaceParam(
303+
prog_id, scene, GLUsdPreviewSurfaceState::kOpacityThreshold,
304+
surfaceShader.opacityThreshold, dst.opacityThreshold)) {
287305
return false;
288306
}
289307

290-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kIor, surfaceShader.ior, dst.ior)) {
308+
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene,
309+
GLUsdPreviewSurfaceState::kIor,
310+
surfaceShader.ior, dst.ior)) {
291311
return false;
292312
}
293313

294-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kOcclusion, surfaceShader.occlusion, dst.occlusion)) {
314+
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene,
315+
GLUsdPreviewSurfaceState::kOcclusion,
316+
surfaceShader.occlusion, dst.occlusion)) {
295317
return false;
296318
}
297319

298-
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene, GLUsdPreviewSurfaceState::kNormal, surfaceShader.normal, dst.normal)) {
320+
if (!SetupGLUsdPreviewSurfaceParam(prog_id, scene,
321+
GLUsdPreviewSurfaceState::kNormal,
322+
surfaceShader.normal, dst.normal)) {
299323
return false;
300324
}
301325

302326
{
303-
GLint loc = glGetUniformLocation(prog_id, GLUsdPreviewSurfaceState::kUseSpecularWorkflow);
327+
GLint loc = glGetUniformLocation(
328+
prog_id, GLUsdPreviewSurfaceState::kUseSpecularWorkflow);
304329
if (loc < 0) {
305-
std::cerr << GLUsdPreviewSurfaceState::kUseSpecularWorkflow << " uniform not found in the shader.\n";
330+
std::cerr << GLUsdPreviewSurfaceState::kUseSpecularWorkflow
331+
<< " uniform not found in the shader.\n";
306332
}
307-
dst.useSpecularWorkflow.factor = surfaceShader.useSpecularWorkFlow ? 1.0f : 0.0f;
333+
dst.useSpecularWorkflow.factor =
334+
surfaceShader.useSpecularWorkFlow ? 1.0f : 0.0f;
308335
dst.useSpecularWorkflow.u_factor = loc;
309336
}
310337

@@ -395,6 +422,9 @@ struct GUIContext {
395422

396423
std::string converter_info;
397424
std::string converter_warn;
425+
426+
std::string vert_filename{"../shaders/no_skinning.vert"};
427+
std::string frag_filename{"../shaders/usdpreviewsurface.frag"};
398428
};
399429

400430
GUIContext gCtx;
@@ -1071,13 +1101,12 @@ static void ComputeBoundingBox(const tinyusdz::tydra::RenderMesh &mesh,
10711101
static bool ProcScene(const example::shader &gl_shader,
10721102
const tinyusdz::Stage &stage,
10731103
std::string &asset_search_path, GLScene *scene) {
1074-
10751104
tinyusdz::Axis upAxis{tinyusdz::Axis::Y};
10761105
if (stage.metas().upAxis.authored()) {
10771106
upAxis = stage.metas().upAxis.get_value();
10781107
}
10791108
std::cout << "upAxis " << tinyusdz::to_string(upAxis) << "\n";
1080-
1109+
10811110
//
10821111
// Stage to Renderable Scene
10831112
//
@@ -1153,7 +1182,8 @@ static bool ProcScene(const example::shader &gl_shader,
11531182
scene_bmax[2] = (std::max)(bmax[2], scene_bmax[2]);
11541183

11551184
GLMeshState gl_mesh;
1156-
if (!SetupMesh(upAxis, renderScene.meshes[i], gl_shader.get_program(), gl_mesh)) {
1185+
if (!SetupMesh(upAxis, renderScene.meshes[i], gl_shader.get_program(),
1186+
gl_mesh)) {
11571187
std::cerr << "SetupMesh for mesh[" << i << "] failed.\n";
11581188
exit(-1);
11591189
}
@@ -1396,7 +1426,7 @@ int main(int argc, char **argv) {
13961426

13971427
std::string filename = "models/suzanne.usdc";
13981428
// std::string filename = "models/texture-cat-plane.usdc";
1399-
//std::string filename = "models/texturedcube.usdc";
1429+
// std::string filename = "models/texturedcube.usdc";
14001430
// std::string filename = "models/simple-plane.usdz";
14011431
#if defined(_MSC_VER)
14021432
std::cout << "cwd: " << _getcwd(nullptr, 0) << "\n";
@@ -1560,6 +1590,24 @@ int main(int argc, char **argv) {
15601590
ImGuiInputTextFlags_ReadOnly);
15611591
ImGui::End();
15621592

1593+
// For developers only
1594+
ImGui::Begin("dev");
1595+
{
1596+
static bool compile_ok{true};
1597+
1598+
if (ImGui::Button("Reload shader")) {
1599+
compile_ok = ReloadShader(curr_shader.get_program(), gCtx.vert_filename,
1600+
gCtx.frag_filename);
1601+
}
1602+
1603+
if (compile_ok) {
1604+
ImGui::TextColored(ImVec4(0.3, 1.0, 0.4, 1.0), "Shader Compile OK");
1605+
} else {
1606+
ImGui::TextColored(ImVec4(1.0, 0.2, 0.1, 1.0), "Shader Compile Failed");
1607+
}
1608+
ImGui::End();
1609+
}
1610+
15631611
ImGui::Begin("Camera");
15641612
ImGui::SliderFloat("fov", &gCtx.fov, 0.0f, 178.0f);
15651613
ImGui::InputFloat("znear", &gCtx.znear);
@@ -1587,8 +1635,6 @@ int main(int argc, char **argv) {
15871635
gCtx.camera.setRotation({gCtx.xrotate, gCtx.yrotate, 0.0f});
15881636
gCtx.camera.setPerspective(gCtx.fov, aspect, gCtx.znear, gCtx.zfar);
15891637

1590-
gCtx.camera.matrices.perspective;
1591-
15921638
ImGui::Begin("View matrix");
15931639
{
15941640
tinyusdz::value::matrix4f view;

src/tydra/nurbs-tess.hh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: Apache 2.0
2+
// Simple NURBS tesselation
3+
4+
#pragma once
5+
6+
#include "render-data.hh"
7+
8+
namespace tinyusdz {
9+
10+
namespace tydra {
11+
12+
struct Nurbs;
13+
14+
class NurbsTesselator
15+
{
16+
bool tesselate(const Nurbs &nurbs, uint32_t u_divs, uint32_t v_divs, RenderMesh &dst );
17+
};
18+
19+
} // namespace tydra
20+
21+
} // namespace tinyusdz

0 commit comments

Comments
 (0)