source: NonGTP/FCollada/FCDocument/FCDEffectPassShader.h @ 964

Revision 964, 6.8 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[964]1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5
6/**
7        @file FCDEffectPassShader.h
8        This file contains the FCDEffectPassShader and the FCDEffectPassBind classes.
9*/
10
11#ifndef _FCD_EFFECT_PASS_SHADER_H_
12#define _FCD_EFFECT_PASS_SHADER_H_
13
14#include "FCDocument/FCDObject.h"
15
16class FCDocument;
17class FCDEffectCode;
18
19/**
20        A COLLADA shader binding.
21
22        Binds an external symbol to a COLLADA effect parameter, by reference.
23
24        @ingroup FCDEffect
25*/
26class FCOLLADA_EXPORT FCDEffectPassBind
27{
28public:
29        string reference; /**< A COLLADA effect parameter reference. */
30        string symbol; /**< An external symbol, used within the shader code. */
31};
32
33typedef vector<FCDEffectPassBind> FCDEffectPassBindList; /**< A dynamically-sized array of shader bindings. */
34
35/**
36        A COLLADA shader.
37
38        The shader abstraction level in ColladaFX is contained within the effect passes.
39        There are two types of shaders: vertex shaders and fragment/pixel shaders.
40        A COLLADA shader contains a list of bindings to attach the effect parameters to the
41        shader input parameters.
42
43        The shader object also contains the compiler information necessary to build
44        the shader: its code, the compiler target and the compiler options.
45*/
46class FCOLLADA_EXPORT FCDEffectPassShader : public FCDObject
47{
48private:
49        DeclareObjectType;
50        FCDEffectPass* parent;
51
52        FCDEffectPassBindList bindings;
53        fstring compilerTarget;
54        fstring compilerOptions;
55        string name;
56        bool isFragment;
57        FCDEffectCode* code;
58
59public:
60        /** Constructor: do not use directly. Instead, use the FCDEffectPass::AddShader,
61                FCDEffectPass::AddVertexShader or FCDEffectPass::AddFragmentShader functions.
62                @param document The COLLADA document that owns this shader.
63                @param parent The effect pass that contains this shader. */
64        FCDEffectPassShader(FCDocument* document, FCDEffectPass* parent);
65
66        /** Destructor: do not use directly.
67                Instead, use the FCDEffectPass::ReleaseShader function. */
68        virtual ~FCDEffectPassShader();
69
70        /** Retrieves the effect pass that contains this shader.
71                @return The effect pass. */
72        inline FCDEffectPass* GetParent() { return parent; }
73        inline const FCDEffectPass* GetParent() const { return parent; } /**< See above. */
74
75        /** Sets this shader as affecting vertices.
76                This sets the stage of the shader to the vertex pipeline. */
77        inline void AffectsVertices() { isFragment = false; }
78
79        /** Sets this shader as affecting fragments/pixels.
80                This sets the stage of the shader to the fragment/pixel pipeline. */
81        inline void AffectsFragments() { isFragment = true; }
82
83        /** Retrieves whether this shader affects fragments/pixels.
84                @return Whether this shader affects fragments/pixels. */
85        inline bool IsFragmentShader() const { return isFragment; }
86
87        /** Retrieves whether this shader affects vertices.
88                @return Whether this shader affects vertices. */
89        inline bool IsVertexShader() const { return !isFragment; }
90
91        /** Retrieves the list of bindings for this shader.
92                @return The list of bindings. */
93        inline FCDEffectPassBindList& GetBindings() { return bindings; }
94        inline const FCDEffectPassBindList& GetBindings() const { return bindings; } /**< See above. */
95
96        /** Retrieves the number of bindings for this shader.
97                @return The number of bindings. */
98        inline size_t GetBindingCount() const { return bindings.size(); }
99       
100        /** Retrieves a binding contained in this shader.
101                @param index The index of the binding.
102                @return The binding. This pointer will be NULL if the index is out-of-bounds. */
103        inline FCDEffectPassBind* GetBinding(size_t index) { FUAssert(index < GetBindingCount(), return NULL); return &bindings.at(index); }
104        inline const FCDEffectPassBind* GetBinding(size_t index) const { FUAssert(index < GetBindingCount(), return NULL); return &bindings.at(index); } /**< See above. */
105
106        /** Adds a new binding to this shader.
107                @return The new binding. */
108        FCDEffectPassBind* AddBinding();
109
110        /** Releases a binding contained within this shader.
111                @param binding The binding to release. */
112        void ReleaseBinding(FCDEffectPassBind* binding);
113
114        /** Retrieves the compiler target information.
115                The validity of this string depends on the type of the profile that contains this shader.
116                @return The compiler target information string. */
117        inline const fstring& GetCompilerTarget() const { return compilerTarget; }
118
119        /** Sets the compiler target information string.
120                The validity of this string depends on the type of the profile that contains this shader.
121                @param _compilerTarget The compiler target information. */
122        inline void SetCompilerTarget(const fstring& _compilerTarget) { compilerTarget = _compilerTarget; }
123
124        /** Retrieves the compiler option string.
125                The validity of this string depends on the type of the profile that contains this shader.
126                @return The compiler option string. */
127        inline const fstring& GetCompilerOptions() const { return compilerOptions; }
128
129        /** Sets the compiler option string.
130                The validity of this string depends on the type of the profile that contains this shader.
131                @param _compilerOptions The compiler option string. */
132        inline void SetCompilerOptions(const fstring& _compilerOptions) { compilerOptions = _compilerOptions; }
133
134        /** Retrieves the sub-id of the shader.
135                @return The sub-id. */
136        inline const string& GetName() const { return name; }
137
138        /** Sets the sub-id of the shader.
139                @param _name The sub-id. */
140        inline void SetName(const string& _name) { name = _name; }
141
142        /** Retrieves the code inclusion that contains the code for this shader.
143                @return The code inclusion. This pointer will be NULL if this shader
144                        is not yet attached to any code. */
145        inline FCDEffectCode* GetCode() { return code; }
146        inline const FCDEffectCode* GetCode() const { return code; } /**< See above. */
147
148        /** Sets the code inclusion that contains the code for this shader.
149                @param _code The code inclusion. This pointer will be NULL to detach
150                         a shader from its code. */
151        inline void SetCode(FCDEffectCode* _code) { code = _code; }
152
153        /** [INTERNAL] Clones this shader. You must manually delete the clone.
154                @param newParent The effect pass that will contain the clone.
155                @return The cloned shader. */
156        FCDEffectPassShader* Clone(FCDEffectPass* newParent) const;
157
158        /** [INTERNAL] Reads in the pass shader from a given COLLADA XML tree node.
159                @param shaderNode The COLLADA XML tree node.
160                @return The status of the import. If the status is not successful,
161                        it may be dangerous to extract information from the shader.*/
162        FUStatus LoadFromXML(xmlNode* shaderNode);
163
164        /** [INTERNAL] Writes out the pass shader to the given COLLADA XML tree node.
165                @param parentNode The COLLADA XML parent node in which to insert the effect profile.
166                @return The created element XML tree node. */
167        xmlNode* WriteToXML(xmlNode* parentNode) const;
168};
169
170#endif // _FCD_EFFECT_PASS_SHADER_H_
Note: See TracBrowser for help on using the repository browser.