Panda3D

Loading...
Searching...
No Matches
shaderAttrib.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file shaderAttrib.h
10 * @author jyelon
11 * @date 2005-09-01
12 * @author fperazzi, PandaSE
13 * @date 2010-04-06
14 * for set_shader_input)
15 * @author weifengh, PandaSE
16 * @date 2010-04-15
17 */
18
19#ifndef SHADERATTRIB_H
20#define SHADERATTRIB_H
21
22#include "pandabase.h"
23#include "renderAttrib.h"
24#include "pointerTo.h"
25#include "shaderInput.h"
26#include "shader.h"
27#include "pta_float.h"
28#include "pta_double.h"
29#include "pta_LMatrix4.h"
30#include "pta_LMatrix3.h"
31#include "pta_LVecBase4.h"
32#include "pta_LVecBase3.h"
33#include "pta_LVecBase2.h"
34#include "extension.h"
35
36/**
37 *
38 */
39 class EXPCL_PANDA_PGRAPH ShaderAttrib: public RenderAttrib {
40 private:
41 INLINE ShaderAttrib();
42 INLINE ShaderAttrib(const ShaderAttrib &copy);
43
44PUBLISHED:
45 static CPT(RenderAttrib) make(const Shader *shader = nullptr, int priority = 0);
46 static CPT(RenderAttrib) make_off();
47 static CPT(RenderAttrib) make_default();
48
49 enum {
50 F_disable_alpha_write = 0, // Suppress writes to color buffer alpha channel.
51 F_subsume_alpha_test = 1, // Shader promises to subsume the alpha test using TEXKILL
52 F_hardware_skinning = 2, // Shader needs pre-animated vertices
53 F_shader_point_size = 3, // Shader provides point size, not RenderModeAttrib
54 };
55
56 INLINE bool has_shader() const;
57 INLINE bool auto_shader() const;
58 INLINE int get_shader_priority() const;
59 INLINE int get_instance_count() const;
60 INLINE bool auto_normal_on() const;
61 INLINE bool auto_glow_on() const;
62 INLINE bool auto_gloss_on() const;
63 INLINE bool auto_ramp_on() const;
64 INLINE bool auto_shadow_on() const;
65
66 CPT(RenderAttrib) set_shader(const Shader *s, int priority=0) const;
67 CPT(RenderAttrib) set_shader_off(int priority=0) const;
68 CPT(RenderAttrib) set_shader_auto(int priority=0) const;
69
70 CPT(RenderAttrib) set_shader_auto(BitMask32 shader_switch, int priority=0) const;
71
72 CPT(RenderAttrib) clear_shader() const;
73 // Shader Inputs
74 CPT(RenderAttrib) set_shader_input(const ShaderInput &input) const;
75 CPT(RenderAttrib) set_shader_input(ShaderInput &&input) const;
76
77 public:
78 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, Texture *tex, int priority=0) const;
79 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const NodePath &np, int priority=0) const;
80 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_float &v, int priority=0) const;
81 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_double &v, int priority=0) const;
82 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LMatrix4 &v, int priority=0) const;
83 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LMatrix3 &v, int priority=0) const;
84 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LVecBase4 &v, int priority=0) const;
85 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LVecBase3 &v, int priority=0) const;
86 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const PTA_LVecBase2 &v, int priority=0) const;
87 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LVecBase4 &v, int priority=0) const;
88 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LVecBase3 &v, int priority=0) const;
89 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LVecBase2 &v, int priority=0) const;
90 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LMatrix4 &v, int priority=0) const;
91 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, const LMatrix3 &v, int priority=0) const;
92 INLINE CPT(RenderAttrib) set_shader_input(CPT_InternalName id, double n1=0, double n2=0, double n3=0, double n4=1,
93 int priority=0) const;
94
95PUBLISHED:
96 EXTENSION(CPT(RenderAttrib) set_shader_input(CPT_InternalName, PyObject *, int priority=0) const);
97 EXTENSION(CPT(RenderAttrib) set_shader_inputs(PyObject *args, PyObject *kwargs) const);
98
99 CPT(RenderAttrib) set_instance_count(int instance_count) const;
100
101 CPT(RenderAttrib) set_flag(int flag, bool value) const;
102 CPT(RenderAttrib) clear_flag(int flag) const;
103
104 CPT(RenderAttrib) clear_shader_input(const InternalName *id) const;
105 CPT(RenderAttrib) clear_shader_input(const std::string &id) const;
106
107 CPT(RenderAttrib) clear_all_shader_inputs() const;
108
109 INLINE bool get_flag(int flag) const;
110 INLINE bool has_shader_input(CPT_InternalName id) const;
111
112 const Shader *get_shader() const;
113 const ShaderInput &get_shader_input(const InternalName *id) const;
114 const ShaderInput &get_shader_input(const std::string &id) const;
115
116 const NodePath &get_shader_input_nodepath(const InternalName *id) const;
117 LVecBase4 get_shader_input_vector(InternalName *id) const;
118 Texture *get_shader_input_texture(const InternalName *id, SamplerState *sampler=nullptr) const;
119 const Shader::ShaderPtrData *get_shader_input_ptr(const InternalName *id) const;
120 const LMatrix4 &get_shader_input_matrix(const InternalName *id, LMatrix4 &matrix) const;
121 ShaderBuffer *get_shader_input_buffer(const InternalName *id) const;
122
123 static void register_with_read_factory();
124
125PUBLISHED:
126 MAKE_PROPERTY(shader, get_shader);
127 MAKE_PROPERTY(instance_count, get_instance_count);
128
129 public:
130 virtual void output(std::ostream &out) const;
131
132 protected:
133 virtual int compare_to_impl(const RenderAttrib *other) const;
134 virtual size_t get_hash_impl() const;
135 virtual CPT(RenderAttrib) compose_impl(const RenderAttrib *other) const;
136
137 private:
138
139 CPT(Shader) _shader;
140 int _shader_priority;
141 bool _auto_shader;
142 bool _has_shader;
143 int _flags;
144 int _has_flags;
145 int _instance_count;
146
147 bool _auto_normal_on;
148 bool _auto_glow_on;
149 bool _auto_gloss_on;
150 bool _auto_ramp_on;
151 bool _auto_shadow_on;
152
153 // We don't keep a reference to the InternalName, since this is also already
154 // stored on the ShaderInput object.
155 typedef pmap<const InternalName *, ShaderInput> Inputs;
156 Inputs _inputs;
157
158 friend class Extension<NodePath>;
159 friend class Extension<ShaderAttrib>;
160
161PUBLISHED:
162 static int get_class_slot() {
163 return _attrib_slot;
164 }
165 virtual int get_slot() const {
166 return get_class_slot();
167 }
168 MAKE_PROPERTY(class_slot, get_class_slot);
169
170 public:
171 static TypeHandle get_class_type() {
172 return _type_handle;
173 }
174 static void init_type() {
175 RenderAttrib::init_type();
176 register_type(_type_handle, "ShaderAttrib",
177 RenderAttrib::get_class_type());
178 _attrib_slot = register_slot(_type_handle, 10, new ShaderAttrib);
179 }
180 virtual TypeHandle get_type() const {
181 return get_class_type();
182 }
183 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
184
185 private:
186 static TypeHandle _type_handle;
187 static int _attrib_slot;
188};
189
190
191#include "shaderAttrib.I"
192
193#endif // SHADERATTRIB_H
CPT_InternalName
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
Definition internalName.h:193
Extension
The default class template does not define any methods.
Definition extension.h:34
InternalName
Encodes a string name in a hash table, mapping it to a pointer.
Definition internalName.h:38
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
RenderAttrib::register_slot
static int register_slot(TypeHandle type_handle, int sort, RenderAttrib *default_attrib)
Adds the indicated TypeHandle to the registry, if it is not there already, and returns a unique slot ...
Definition renderAttrib.I:101
SamplerState
Represents a set of settings that indicate how a texture is sampled.
Definition samplerState.h:36
ShaderAttrib::make_off
static ConstPointerTo< RenderAttrib > make_off()
Constructs a new ShaderAttrib object that disables the use of shaders (it does not clear out all shad...
Definition shaderAttrib.cxx:43
ShaderAttrib::clear_all_shader_inputs
ConstPointerTo< RenderAttrib > clear_all_shader_inputs() const
Clears all the shader inputs on the attrib.
Definition shaderAttrib.cxx:261
ShaderAttrib::get_shader_input_texture
Texture * get_shader_input_texture(const InternalName *id, SamplerState *sampler=nullptr) const
Returns the ShaderInput as a texture.
Definition shaderAttrib.cxx:410
ShaderAttrib::auto_shader
bool auto_shader() const
If true, then this ShaderAttrib does not contain an explicit shader - instead, it requests the automa...
Definition shaderAttrib.I:71
ShaderAttrib::get_shader_input_matrix
const LMatrix4 & get_shader_input_matrix(const InternalName *id, LMatrix4 &matrix) const
Returns the ShaderInput as a matrix.
Definition shaderAttrib.cxx:453
ShaderAttrib::has_shader_input
bool has_shader_input(CPT_InternalName id) const
Returns true if there is a ShaderInput of the given name.
Definition shaderAttrib.I:104
ShaderAttrib::get_shader
get_shader
Returns the shader object associated with the node.
Definition shaderAttrib.h:126
ShaderAttrib::get_shader_input_buffer
ShaderBuffer * get_shader_input_buffer(const InternalName *id) const
Returns the ShaderInput as a ShaderBuffer.
Definition shaderAttrib.cxx:506
ShaderAttrib::get_shader_input_nodepath
const NodePath & get_shader_input_nodepath(const InternalName *id) const
Returns the ShaderInput as a nodepath.
Definition shaderAttrib.cxx:295
ShaderAttrib::make
static ConstPointerTo< RenderAttrib > make(const Shader *shader=nullptr, int priority=0)
Constructs a new ShaderAttrib object with nothing set.
Definition shaderAttrib.cxx:57
ShaderAttrib::set_instance_count
ConstPointerTo< RenderAttrib > set_instance_count(int instance_count) const
Sets the geometry instance count.
Definition shaderAttrib.cxx:233
ShaderAttrib::get_shader_input
const ShaderInput & get_shader_input(const InternalName *id) const
Returns the ShaderInput of the given name.
Definition shaderAttrib.cxx:272
ShaderAttrib::register_with_read_factory
static void register_with_read_factory()
Factory method to generate a Shader object.
Definition shaderAttrib.cxx:722
ShaderAttrib::make_default
static ConstPointerTo< RenderAttrib > make_default()
Returns a RenderAttrib that corresponds to whatever the standard default properties for render attrib...
Definition shaderAttrib.cxx:76
ShaderAttrib::get_instance_count
get_instance_count
Returns the number of geometry instances.
Definition shaderAttrib.h:127
ShaderAttrib::has_shader
bool has_shader() const
If true, the shader field of this attribute overrides the shader field of the parent attribute.
Definition shaderAttrib.I:62
ShaderAttrib::get_shader_input_ptr
const Shader::ShaderPtrData * get_shader_input_ptr(const InternalName *id) const
Returns the ShaderInput as a ShaderPtrData struct.
Definition shaderAttrib.cxx:382
ShaderAttrib::get_shader_input_vector
LVecBase4 get_shader_input_vector(InternalName *id) const
Returns the ShaderInput as a vector.
Definition shaderAttrib.cxx:324
ShaderBuffer
This is a generic buffer object that lives in graphics memory.
Definition shaderBuffer.h:33
ShaderInput
This is a small container class that can hold any one of the value types that can be passed as input ...
Definition shaderInput.h:40
Shader
Definition shader.h:49
Texture
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
Definition texture.h:72
extension.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_LMatrix3.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_LMatrix4.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_LVecBase2.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_LVecBase3.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_LVecBase4.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_double.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pta_float.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22
renderAttrib.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
shaderAttrib.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
shaderInput.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
shader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Shader::ShaderPtrData
Definition shader.h:373