Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Samples/OceanDemo/include/MaterialControls.h @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 4.4 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL like the rest of the engine.
12-----------------------------------------------------------------------------
13*/
14
15#ifndef __MaterialControls_H__
16#define __MaterialControls_H__
17
18#include "CEGUI/CEGUIForwardRefs.h"
19#include "OgreString.h"
20
21enum ShaderValType
22{
23        GPU_VERTEX, GPU_FRAGMENT, MAT_SPECULAR, MAT_DIFFUSE, MAT_AMBIENT, MAT_SHININESS, MAT_EMISSIVE
24};
25
26//---------------------------------------------------------------------------
27struct ShaderControl
28{
29    Ogre::String Name;
30        Ogre::String ParamName;
31        ShaderValType ValType;
32        float MinVal;
33        float MaxVal;
34        size_t ElementIndex;
35        mutable size_t PhysicalIndex;
36
37        float getRange(void) const { return MaxVal - MinVal; }
38        float convertParamToScrollPosition(const float val) const { return val - MinVal; }
39        float convertScrollPositionToParam(const float val) const { return val + MinVal; }
40};
41
42typedef std::vector<ShaderControl> ShaderControlsContainer;
43typedef ShaderControlsContainer::iterator ShaderControlIterator;
44// used for materials that have user controls
45
46//---------------------------------------------------------------------------
47class MaterialControls
48{
49public:
50    MaterialControls(const Ogre::String& displayName, const Ogre::String& materialName)
51        : mDisplayName(displayName)
52        , mMaterialName(materialName)
53    {
54    };
55
56    ~MaterialControls(void){}
57
58    const Ogre::String& getDisplayName(void) const { return mDisplayName; }
59    const Ogre::String& getMaterialName(void) const { return mMaterialName; }
60    size_t getShaderControlCount(void) const { return mShaderControlsContainer.size(); }
61    const ShaderControl& getShaderControl(const size_t idx) const
62    {
63        assert( idx < mShaderControlsContainer.size() );
64        return mShaderControlsContainer[idx];
65    }
66    /** add a new control by passing a string parameter
67
68    @param
69      params is a string using the following format:
70        "<Control Name>, <Shader parameter name>, <Parameter Type>, <Min Val>, <Max Val>, <Parameter Sub Index>"
71
72        <Control Name> is the string displayed for the control name on screen
73        <Shader parameter name> is the name of the variable in the shader
74        <Parameter Type> can be GPU_VERTEX, GPU_FRAGMENT
75        <Min Val> minimum value that parameter can be
76        <Max Val> maximum value that parameter can be
77        <Parameter Sub Index> index into the the float array of the parameter.  All GPU parameters are assumed to be float[4].
78
79    */
80    void addControl(const Ogre::String& params);
81
82protected:
83
84    Ogre::String mDisplayName;
85    Ogre::String mMaterialName;
86
87    ShaderControlsContainer mShaderControlsContainer;
88};
89
90typedef std::vector<MaterialControls> MaterialControlsContainer;
91typedef MaterialControlsContainer::iterator MaterialControlsIterator;
92
93
94//---------------------------------------------------------------------------
95struct ShaderControlGUIWidget
96{
97        CEGUI::Window* TextWidget;
98        CEGUI::Window* NumberWidget;
99        CEGUI::Scrollbar*  ScrollWidget;
100
101        ShaderControlGUIWidget() : TextWidget(NULL), NumberWidget(NULL), ScrollWidget(NULL) {}
102};
103
104//---------------------------------------------------------------------------
105/** loads material shader controls from a configuration file
106    A .controls file is made up of the following:
107
108    [<material display name>]
109    material = <material name>
110    control = <Control Name>, <Shader parameter name>, <Parameter Type>, <Min Val>, <Max Val>, <Parameter Sub Index>
111
112    <material display name> is what is displayed in the material combo box.
113    <material name> is the name of the material in the material script.
114    control is the shader control associated with the material. The order
115    of the contol definions in the .controls file determins their order
116    when displayed in the controls window.
117
118    you can have multiple .controls files or put them all in one.
119*/
120void loadMaterialControlsFile(MaterialControlsContainer& controlsContainer, const Ogre::String& filename);
121/** load all control files found in resource paths
122*/
123void loadAllMaterialControlFiles(MaterialControlsContainer& controlsContainer);
124
125#endif // __MaterialControls_H__
Note: See TracBrowser for help on using the repository browser.