ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/material.h
Revision: 1.16
Committed: Wed Nov 3 03:35:13 2004 UTC (19 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.15: +36 -27 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 (const shader::gluvar &vertex = shader::compile::vin.vertex)
14 {
15 using namespace shader::compile;
16
17 vout.position = model_view_projection_matrix * vertex;
18 }
19
20 struct material
21 {
22
23 // the vertex shader fragment. it should check ctx.pass_data->light and
24 // only generate varying data when light is non-null. it should also use
25 // std_vsh () whenever possible.
26
27 virtual void vsh (view &ctx) = 0;
28
29 // the fragment shader fragment :). it should check ctx.pass_data->light
30 // and, if null, best do nothing. if non-null, it should call
31 // light->value to get the per-pixel light colour and apply it to the
32 // surface as neccessary.
33
34 virtual void fsh (view &ctx) = 0;
35
36 virtual void enable (view &ctx);
37 virtual void disable (view &ctx);
38
39 virtual ~material ();
40 };
41
42 struct texture_execption
43 {
44 texture_execption (string s) : msg(s) { }
45 string msg;
46 };
47
48 struct texture
49 {
50 SDL_Surface *image;
51 GLuint name;
52 GLfloat texcoord[4];
53
54 GLuint load_texture (SDL_Surface *surface, GLfloat *texcoord);
55
56 texture (const char *f)
57 {
58 image = IMG_Load (f);
59
60 if (!image)
61 throw (texture_execption ("Couldn't load " + (string) f + ": " + (string) IMG_GetError ()));
62
63 name = load_texture (image, (GLfloat*)&texcoord);
64 if (name == 0)
65 throw (texture_execption ("Couldn't make GL Texture, failed to create new RGB SWSurface"));
66 }
67 };
68
69 struct test_material : material
70 {
71 texture tex, norm;
72 shader::sampler_2d texvar, normvar;
73
74 void vsh (view &ctx);
75 void fsh (view &ctx);
76
77 void enable (view &ctx);
78 void disable (view &ctx);
79
80 test_material ();
81 };
82
83 extern test_material testmat;
84
85 #endif
86
87