ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/material.h
Revision: 1.20
Committed: Mon Feb 7 08:51:18 2005 UTC (19 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.19: +11 -5 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #ifndef MATERIAL_H
2 #define MATERIAL_H
3
4 #include <vector>
5 #include <string>
6 #include <sstream>
7
8 using namespace std;
9
10 #include "util.h"
11 #include "shader.h"
12
13 inline void std_vsh ()
14 {
15 using namespace shader::compile;
16
17 vout.position = ftransform ();
18 }
19
20 inline void std_vsh (const shader::gluvar &vertex)
21 {
22 using namespace shader::compile;
23
24 vout.position = model_view_projection_matrix * vertex;
25 }
26
27 struct material
28 {
29
30 // the vertex shader fragment. it should check ctx.pass_data->light and
31 // only generate varying data when light is non-null. it should also use
32 // std_vsh () whenever possible.
33
34 virtual void vsh (view &ctx) = 0;
35
36 // the fragment shader fragment :). it should check ctx.pass_data->light
37 // and, if null, best do nothing. if non-null, it should call
38 // light->value to get the per-pixel light colour and apply it to the
39 // surface as neccessary.
40
41 virtual void fsh (view &ctx) = 0;
42
43 virtual void enable (view &ctx);
44 virtual void disable (view &ctx);
45
46 virtual ~material ();
47 };
48
49 struct texture_execption
50 {
51 texture_execption (string s) : msg(s) { }
52 string msg;
53 };
54
55 struct texture
56 {
57 SDL_Surface *image;
58 GLuint name;
59 GLfloat texcoord[4];
60
61 GLuint load_texture (SDL_Surface *surface, GLfloat *texcoord);
62
63 texture (const char *f)
64 {
65 image = IMG_Load (f);
66
67 if (!image)
68 throw (texture_execption ("Couldn't load " + (string) f + ": " + (string) IMG_GetError ()));
69
70 name = load_texture (image, (GLfloat*)&texcoord);
71 if (name == 0)
72 throw (texture_execption ("Couldn't make GL Texture, failed to create new RGB SWSurface"));
73 }
74 };
75
76 struct test_material : material
77 {
78 texture tex, norm;
79 shader::sampler_2d texvar, normvar;
80
81 void vsh (view &ctx);
82 void fsh (view &ctx);
83
84 void enable (view &ctx);
85 void disable (view &ctx);
86
87 test_material ();
88 };
89
90 struct mat_gouraud_shaded : material
91 {
92 // texture tex, norm;
93 // shader::sampler_2d texvar, normvar;
94 colour c;
95
96 void vsh (view &ctx);
97 void fsh (view &ctx);
98
99 void enable (view &ctx);
100 void disable (view &ctx);
101
102 mat_gouraud_shaded (const colour &c) : c(c) { }
103
104 protected:
105 shader::uniform_3f sh_colour;
106 shader::varying_3f f_normal;
107 };
108
109 extern test_material *testmat;
110 extern mat_gouraud_shaded *testmat2;
111
112 #endif
113
114