mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2024-12-02 00:00:07 +00:00
f7f2ca2581
Important notice: all client shader code must have following functions and compose them to osd intrinsic shaders (vertex/tessEval/tessControl) mat4 OsdModelViewMatrix() mat4 OsdProjectionMatrix() mat4 OsdModelViewProjectionMatrix() float OsdTessLevel() int OsdGreogryQuadOffsetBase() int OsdPrimitiveIdBase() We probably should write a utility class for basic binding of them, to make client code simpler.
102 lines
3.1 KiB
C++
102 lines
3.1 KiB
C++
//
|
|
// Copyright 2013 Pixar
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "Apache License")
|
|
// with the following modification; you may not use this file except in
|
|
// compliance with the Apache License and the following modification to it:
|
|
// Section 6. Trademarks. is deleted and replaced with:
|
|
//
|
|
// 6. Trademarks. This License does not grant permission to use the trade
|
|
// names, trademarks, service marks, or product names of the Licensor
|
|
// and its affiliates, except as required to comply with Section 4(c) of
|
|
// the License and to reproduce the content of the NOTICE file.
|
|
//
|
|
// You may obtain a copy of the Apache License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the Apache License with the above modification is
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the Apache License for the specific
|
|
// language governing permissions and limitations under the Apache License.
|
|
//
|
|
|
|
#ifndef EFFECT_H
|
|
#define EFFECT_H
|
|
|
|
#include <osd/glDrawRegistry.h>
|
|
|
|
#include <osd/opengl.h>
|
|
|
|
enum DisplayTyle { kWire = 0,
|
|
kShaded,
|
|
kWireShaded,
|
|
kVaryingColor,
|
|
kFaceVaryingColor };
|
|
|
|
union EffectDesc {
|
|
public:
|
|
struct {
|
|
unsigned int displayStyle:3;
|
|
unsigned int screenSpaceTess:1;
|
|
};
|
|
int value;
|
|
|
|
bool operator < (const EffectDesc &e) const {
|
|
return value < e.value;
|
|
}
|
|
|
|
int GetDisplayStyle() const { return displayStyle; }
|
|
bool GetScreenSpaceTess() const { return screenSpaceTess; }
|
|
};
|
|
|
|
struct MyDrawConfig : public OpenSubdiv::OsdGLDrawConfig {
|
|
|
|
MyDrawConfig() :
|
|
diffuseColorUniform(-1) {}
|
|
virtual ~MyDrawConfig() {}
|
|
|
|
GLint diffuseColorUniform;
|
|
|
|
GLint gregoryQuadOffsetBaseUniform;
|
|
GLint primitiveIdBaseUniform;
|
|
};
|
|
|
|
class MyEffect { // formerly EffectHandle
|
|
public:
|
|
MyEffect() : displayPatchColor(false), screenSpaceTess(false), displayStyle(kWire) {}
|
|
|
|
EffectDesc GetEffectDescriptor() const {
|
|
EffectDesc desc;
|
|
|
|
desc.value = 0;
|
|
desc.displayStyle = displayStyle;
|
|
desc.screenSpaceTess = screenSpaceTess;
|
|
|
|
return desc;
|
|
}
|
|
|
|
void BindDrawConfig(MyDrawConfig *config, OpenSubdiv::OsdDrawContext::PatchDescriptor desc);
|
|
|
|
void SetMatrix(const float *modelview, const float *projection);
|
|
void SetTessLevel(float tessLevel);
|
|
void SetLighting();
|
|
|
|
bool operator == (const MyEffect &other) const {
|
|
return (displayPatchColor == other.displayPatchColor) and
|
|
(screenSpaceTess == other.screenSpaceTess) and
|
|
(displayStyle == other.displayStyle);
|
|
}
|
|
bool operator != (const MyEffect &other) const {
|
|
return !(*this == other);
|
|
}
|
|
|
|
bool displayPatchColor; // runtime switchable
|
|
bool screenSpaceTess; // need recompile (should be considered in effect descriptor)
|
|
int displayStyle; // need recompile
|
|
};
|
|
|
|
|
|
#endif /* EFFECT_H */
|