New export through plugin scheme for yafray. It is working on linux and mac os x
[blender.git] / source / blender / yafray / intern / yafexternal.h
1 #ifndef __YAFINTERFACE_H
2 #define __YAFINTERFACE_H
3
4 #include<vector>
5 #include<string>
6 #include<list>
7 #include<map>
8
9 namespace yafray
10 {
11
12 typedef float PFLOAT;
13 typedef float GFLOAT;
14 typedef float CFLOAT;
15
16 class point3d_t
17 {
18         public:
19                 point3d_t() { x = y = z = 0; }
20                 point3d_t(PFLOAT ix, PFLOAT iy, PFLOAT iz=0) { x=ix;  y=iy;  z=iz; }
21                 point3d_t(const point3d_t &s) { x=s.x;  y=s.y;  z=s.z; }
22                 void set(PFLOAT ix, PFLOAT iy, PFLOAT iz=0) { x=ix;  y=iy;  z=iz; }
23                 point3d_t& operator= (const point3d_t &s) { x=s.x;  y=s.y;  z=s.z;  return *this; }
24                 ~point3d_t() {};
25                 PFLOAT x,y,z;
26 };
27
28 class color_t
29 {
30         public:
31                 color_t() {R=G=B=0;};
32                 color_t(CFLOAT r,CFLOAT g,CFLOAT b) {R=r;G=g;B=b;};
33                 ~color_t() {};
34                 void set(CFLOAT r,CFLOAT g,CFLOAT b) {R=r;G=g;B=b;};
35
36                 CFLOAT R,G,B;
37 };
38
39 class colorA_t : public color_t
40 {
41         public:
42                 colorA_t() { A=1; }
43                 colorA_t(const color_t &c):color_t(c) { A=1; }
44                 colorA_t(CFLOAT r, CFLOAT g, CFLOAT b, CFLOAT a=0):color_t(r,g,b) {A=a;}
45                 ~colorA_t() {};
46                 void set(CFLOAT r, CFLOAT g, CFLOAT b, CFLOAT a=0) {color_t::set(r,g,b);A=a; };
47
48         protected:
49                 CFLOAT A;
50 };
51
52 #define TYPE_FLOAT  0
53 #define TYPE_STRING 1
54 #define TYPE_POINT  2
55 #define TYPE_COLOR  3
56 #define TYPE_NONE   -1
57
58 class parameter_t
59 {
60         public:
61                 parameter_t(const std::string &s):type(TYPE_STRING),used(false),str(s) {};
62                 parameter_t(float f):type(TYPE_FLOAT),used(false),fnum(f) {};
63                 parameter_t(const colorA_t &c):type(TYPE_COLOR),used(false)
64                         ,C(c) {};
65                 parameter_t(const point3d_t &p):type(TYPE_POINT),used(false),P(p) {};
66                 parameter_t():type(TYPE_NONE),used(false) {};
67                 const std::string               &getStr() {used=true;return str;};
68                 float                                   &getFnum() {used=true;return fnum;};
69                 const point3d_t &getP() {used=true;return P;};
70                 const color_t   &getC() {used=true;return C;};
71                 const colorA_t  &getAC() {used=true;return C;};
72                 int type;
73                 bool used;
74         protected:
75                 std::string str;
76                 float fnum;
77                 point3d_t P;
78                 colorA_t C;
79 };
80
81 class paramMap_t : public std::map<std::string,parameter_t>
82 {
83         public:
84                 virtual bool getParam(const std::string &name,std::string &s);
85                 virtual bool getParam(const std::string &name,bool &b);
86                 virtual bool getParam(const std::string &name,float &f);
87                 virtual bool getParam(const std::string &name,double &f);
88                 virtual bool getParam(const std::string &name,int &i);
89                 virtual bool getParam(const std::string &name,point3d_t &p);
90                 virtual bool getParam(const std::string &name,color_t &c);
91                 virtual bool getParam(const std::string &name,colorA_t &c);
92                 virtual bool includes(const std::string &label,int type);
93                 virtual void checkUnused(const std::string &env);
94                 virtual ~paramMap_t() {};
95 };
96
97 class light_t;
98 class shader_t;
99 class texture_t;
100 class filter_t;
101 class background_t;
102
103 class renderEnvironment_t
104 {
105         public:
106                 typedef light_t * light_factory_t(paramMap_t &,renderEnvironment_t &);
107                 typedef shader_t *shader_factory_t(paramMap_t &,std::list<paramMap_t> &,
108                                 renderEnvironment_t &);
109                 typedef texture_t *texture_factory_t(paramMap_t &,renderEnvironment_t &);
110                 typedef filter_t *filter_factory_t(paramMap_t &,renderEnvironment_t &);
111                 typedef background_t *background_factory_t(paramMap_t &,renderEnvironment_t &);
112                 
113                 virtual shader_t *getShader(const std::string name)const=0;
114                 virtual texture_t *getTexture(const std::string name)const=0;
115
116                 virtual void repeatFirstPass()=0;
117
118                 virtual void registerFactory(const std::string &name,light_factory_t *f)=0;
119                 virtual void registerFactory(const std::string &name,shader_factory_t *f)=0;
120                 virtual void registerFactory(const std::string &name,texture_factory_t *f)=0;
121                 virtual void registerFactory(const std::string &name,filter_factory_t *f)=0;
122                 virtual void registerFactory(const std::string &name,background_factory_t *f)=0;
123
124                 renderEnvironment_t() {};
125                 virtual ~renderEnvironment_t() {};
126
127 };
128
129 class colorOutput_t
130 {
131         public:
132                 virtual ~colorOutput_t() {};
133                 virtual bool putPixel(int x, int y,const color_t &c, 
134                                 CFLOAT alpha=0,PFLOAT depth=0)=0;
135                 virtual void flush()=0;
136 };
137
138 class yafrayInterface_t : public renderEnvironment_t
139 {
140         public:
141                 virtual void transformPush(float *m)=0;
142                 virtual void transformPop()=0;
143                 virtual void addObject_trimesh(const std::string &name,
144                                 std::vector<point3d_t> *verts, const std::vector<int> &faces,
145                                 std::vector<GFLOAT> *uvcoords, std::vector<CFLOAT> *vcol,
146                                 const std::vector<std::string> &shaders,const std::vector<int> &faceshader,
147                                 float sm_angle,bool castShadows,bool useR,bool receiveR,bool caus,bool has_orco,
148                                 const color_t &caus_rcolor,const color_t &caus_tcolor,float caus_IOR)=0;
149
150                 virtual void addObject_reference(const std::string &name,const std::string &original)=0;
151                 // lights
152                 virtual void addLight(paramMap_t &p)=0;
153     // textures
154                 virtual void addTexture(paramMap_t &p)=0;
155                 // shaders
156                 virtual void addShader(paramMap_t &p,std::list<paramMap_t> &modulators)=0;
157                 // filters
158                 virtual void addFilter(paramMap_t &p)=0;
159                 // backgrounds
160                 virtual void addBackground(paramMap_t &p)=0;
161                 //camera
162     virtual void addCamera(paramMap_t &p)=0;
163                 //render
164                 virtual void render(paramMap_t &p)=0;
165                 //render
166                 virtual void render(paramMap_t &p,colorOutput_t &output)=0;
167                 
168                 virtual void clear()=0;
169
170                 virtual ~yafrayInterface_t() {};
171 };
172
173 typedef yafrayInterface_t * yafrayConstructor(int,const std::string &);
174
175 }
176
177 #define YAFRAY_SYMBOL "getYafray"
178
179 #endif