1 #ifndef COIN_SOSHAPE_BUMPRENDER_H
2 #define COIN_SOSHAPE_BUMPRENDER_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/SbVec3f.h>
37 #include <Inventor/SbVec2f.h>
38 #include <Inventor/SbVec2s.h>
39 #include <Inventor/lists/SbList.h>
40 #include <Inventor/SoPrimitiveVertex.h>
41 #include <Inventor/C/glue/gl.h>
42 
43 #include "misc/SbHash.h"
44 
45 // *************************************************************************
46 
47 class SoState;
48 class SoLight;
49 class SoGLImage;
50 class SbMatrix;
51 class SoPrimitiveVertexCache;
52 
53 // *************************************************************************
54 
55 // FIXME: inherit from SoCache to avoid regenerating everything every frame
56 
57 class soshape_bumprender {
58 public:
59   soshape_bumprender(void);
60   ~soshape_bumprender();
61 
62   void calcTangentSpace(const SoPrimitiveVertexCache * cache);
63   void renderBump(SoState * state,
64                   const SoPrimitiveVertexCache * cache,
65                   SoLight * light, const SbMatrix & toobjectspace);
66   void renderBumpSpecular(SoState * state,
67                           const SoPrimitiveVertexCache * cache,
68                           SoLight * light, const SbMatrix & toobjectspace);
69   void renderNormal(SoState * state, const SoPrimitiveVertexCache * cache);
70 
71 private:
72 
73   void initLight(SoLight * light, const SbMatrix & m);
74   void calcTSBCoords(const SoPrimitiveVertexCache * cache, SoLight * light);
75   SbVec3f getLightVec(const SbVec3f & v) const;
76   void initPrograms(const cc_glglue * glue, SoState * state);
77   void initDiffusePrograms(const cc_glglue * glue, SoState * state);
78 
79   void soshape_diffuseprogramdeletion(unsigned long key, void * value);
80   void soshape_specularprogramdeletion(unsigned long key, void * value);
81 
82   struct spec_programidx {
83     const cc_glglue * glue;
84     GLuint dirlight;
85     GLuint pointlight;
86     GLuint fragment;
87   };
88 
89   struct diffuse_programidx {
90     const cc_glglue * glue;
91     GLuint pointlight; // Pointlight diffuse rendering not implemented as a program yet.
92     GLuint dirlight;
93     GLuint normalrendering;
94   };
95 
96   SbList <SbVec3f> cubemaplist;
97   SbList <SbVec3f> tangentlist;
98 
99   SbVec3f lightvec;
100   SbBool ispointlight;
101 
102   typedef SbHash<int, struct diffuse_programidx *> ContextId2DiffuseStruct;
103   ContextId2DiffuseStruct diffuseprogramdict;
104 
105   typedef SbHash<int, struct spec_programidx *> ContextId2SpecStruct;
106   ContextId2SpecStruct specularprogramdict;
107 
108   GLuint fragmentprogramid;
109   GLuint dirlightvertexprogramid;
110   GLuint pointlightvertexprogramid;
111   SbBool programsinitialized;
112 
113   GLuint normalrenderingvertexprogramid;
114   GLuint diffusebumpdirlightvertexprogramid;
115   SbBool diffuseprogramsinitialized;
116 };
117 
118 #endif // COIN_SOSHAPE_BUMPRENDER
119