root/OpenSceneGraph/trunk/examples/osggameoflife/GameOfLifePass.h @ 13363

Revision 12292, 2.8 kB (checked in by robert, 7 years ago)

Ran svn propset -R svn:eol-style native . on the OpenSceneGraph

  • Property svn:eol-style set to native
Line 
1/* OpenSceneGraph example, osggameoflife.
2*
3*  Permission is hereby granted, free of charge, to any person obtaining a copy
4*  of this software and associated documentation files (the "Software"), to deal
5*  in the Software without restriction, including without limitation the rights
6*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7*  copies of the Software, and to permit persons to whom the Software is
8*  furnished to do so, subject to the following conditions:
9*
10*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
11*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
12*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
13*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
15*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
16*  THE SOFTWARE.
17*/
18
19#ifndef GAMEOFLIFEPASS_H
20#define GAMEOFLIFEPASS_H 1
21
22#include <osg/ref_ptr>
23#include <osg/Group>
24#include <osg/Switch>
25#include <osg/Camera>
26#include <osg/Geode>
27#include <osg/Geometry>
28#include <osg/Texture2D>
29#include <osg/TextureRectangle>
30
31class ProcessPass {
32  public:
33    ProcessPass(osg::TextureRectangle *in_tex,
34                osg::TextureRectangle *out_tex,
35                int width, int height);
36    ~ProcessPass();
37    osg::ref_ptr<osg::Group> getRoot() { return _RootGroup; }
38    osg::ref_ptr<osg::TextureRectangle> getOutputTexture() { return _OutTexture; }
39    void setShader(std::string filename);
40   
41  private:
42    osg::ref_ptr<osg::Group> createTexturedQuad();
43    void setupCamera();
44
45    osg::ref_ptr<osg::Group> _RootGroup;
46    osg::ref_ptr<osg::Camera> _Camera;
47    osg::ref_ptr<osg::TextureRectangle> _InTexture;
48    osg::ref_ptr<osg::TextureRectangle> _OutTexture;
49    int _TextureWidth;
50    int _TextureHeight;
51    osg::ref_ptr<osg::Program> _FragmentProgram;
52    osg::ref_ptr<osg::StateSet> _StateSet;
53};
54
55class GameOfLifePass {
56  public:
57    GameOfLifePass(osg::Image *in_image);
58    ~GameOfLifePass();
59    osg::ref_ptr<osg::Group> getRoot() { return _RootGroup; }
60    osg::ref_ptr<osg::TextureRectangle> getOutputTexture();
61    void setShader(std::string filename);
62    // Switch branches so we flip textures
63    void flip();
64
65  private:
66    osg::ref_ptr<osg::Group> createTexturedQuad();
67    void setupCamera();
68    void createOutputTextures();
69    void activateBranch();
70   
71    osg::ref_ptr<osg::Group> _RootGroup;
72    osg::ref_ptr<osg::Camera> _Camera;
73    osg::ref_ptr<osg::TextureRectangle> _InOutTextureLife[2];
74    int _TextureWidth;
75    int _TextureHeight;
76    int _ActiveBranch;
77    osg::ref_ptr<osg::Program> _FragmentProgram;
78    osg::ref_ptr<osg::StateSet> _StateSet;
79    osg::ref_ptr<osg::Switch> _BranchSwith[2];
80    ProcessPass *_ProcessPass[2];
81};
82
83#endif //GAMEOFLIFEPASS_H
Note: See TracBrowser for help on using the browser.