Panda3D
Loading...
Searching...
No Matches
shaderInput.cxx
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 shaderInput.cxx
10 * @author jyelon
11 * @date 2005-09-01
12 */
13
14#include "shaderInput.h"
15#include "paramNodePath.h"
16#include "paramTexture.h"
17
18/**
19 * Returns a static ShaderInput object with name NULL, priority zero, type
20 * INVALID, and all value-fields cleared.
21 */
23get_blank() {
24 static ShaderInput blank(nullptr, 0);
25 return blank;
26}
27
28/**
29 *
30 */
31ShaderInput::
32ShaderInput(CPT_InternalName name, const NodePath &np, int priority) :
33 _name(std::move(name)),
34 _type(M_nodepath),
35 _priority(priority),
36 _value(new ParamNodePath(np))
37{
38}
39
40/**
41 *
42 */
43ShaderInput::
44ShaderInput(CPT_InternalName name, Texture *tex, bool read, bool write, int z, int n, int priority) :
45 _name(std::move(name)),
46 _type(M_texture_image),
47 _priority(priority),
48 _value(new ParamTextureImage(tex, read, write, z, n))
49{
50}
51
52/**
53 *
54 */
55ShaderInput::
56ShaderInput(CPT_InternalName name, Texture *tex, const SamplerState &sampler, int priority) :
57 _name(std::move(name)),
58 _type(M_texture_sampler),
59 _priority(priority),
60 _value(new ParamTextureSampler(tex, sampler))
61{
62}
63
64/**
65 *
66 */
67size_t ShaderInput::
68add_hash(size_t hash) const {
69 hash = int_hash::add_hash(hash, _type);
70 hash = pointer_hash::add_hash(hash, _name);
71 hash = int_hash::add_hash(hash, _priority);
72
73 switch (_type) {
74 case M_invalid:
75 return hash;
76
77 case M_vector:
78 return _stored_vector.add_hash(hash);
79
80 case M_numeric:
81 return pointer_hash::add_hash(hash, _stored_ptr._ptr);
82
83 default:
84 return pointer_hash::add_hash(hash, _value);
85 }
86}
87
88/**
89 * Warning: no error checking is done. This *will* crash if get_value_type()
90 * is not M_nodepath.
91 */
93get_nodepath() const {
94 return DCAST(ParamNodePath, _value)->get_value();
95}
96
97/**
98 *
99 */
100Texture *ShaderInput::
101get_texture() const {
102 switch (_type) {
103 case M_texture_sampler:
104 return DCAST(ParamTextureSampler, _value)->get_texture();
105
106 case M_texture_image:
107 return DCAST(ParamTextureImage, _value)->get_texture();
108
109 case M_texture:
110 return DCAST(Texture, _value);
111
112 default:
113 return nullptr;
114 }
115}
116
117/**
118 * Warning: no error checking is done.
119 */
121get_sampler() const {
122 if (_type == M_texture_sampler) {
123 return DCAST(ParamTextureSampler, _value)->get_sampler();
124
125 } else if (!_value.is_null()) {
126 return get_texture()->get_default_sampler();
127
128 } else {
130 }
131}
132
133/**
134 *
135 */
136void ShaderInput::
137register_with_read_factory() {
138 // IMPLEMENT ME
139}
This is a const pointer to an InternalName, and should be used in lieu of a CPT(InternalName) in func...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition nodePath.h:159
A class object for storing a NodePath as a parameter.
A class object for storing a pointer to a Texture along with a set of properties that indicates which...
A class object for storing a pointer to a Texture along with a sampler state that indicates how to to...
Represents a set of settings that indicate how a texture is sampled.
static const SamplerState & get_default()
Returns a reference to the global default immutable SamplerState object.
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
const NodePath & get_nodepath() const
Warning: no error checking is done.
const SamplerState & get_sampler() const
Warning: no error checking is done.
static const ShaderInput & get_blank()
Returns a static ShaderInput object with name NULL, priority zero, type INVALID, and all value-fields...
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
get_default_sampler
This returns the default sampler state for this texture, containing the wrap and filter properties sp...
Definition texture.h:422
static size_t add_hash(size_t start, const Key &key)
Adds the indicated key into a running hash.
static size_t add_hash(size_t start, const void *key)
Adds the indicated key into a running hash.
STL namespace.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.