00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef MMSFBBACKENDINTERFACE_H_
00034 #define MMSFBBACKENDINTERFACE_H_
00035
00036 #include "mmstools/mmsthreadserver.h"
00037 #include "mmsgui/fb/mmsfbsurface.h"
00038 #include "mmsgui/fb/mmsfbgl.h"
00039
00040 #ifdef __HAVE_OPENGL__
00041
00042 #define __HAVE_MMS3D__
00043
00044 #endif
00045
00046 class MMSFBBackEndInterface : public MMSThreadServer {
00047 private:
00048 typedef enum {
00049 BEI_REQUEST_TYPE_INIT = 0,
00050 BEI_REQUEST_TYPE_SWAP,
00051 BEI_REQUEST_TYPE_ALLOC,
00052 BEI_REQUEST_TYPE_FREE,
00053 BEI_REQUEST_TYPE_CLEAR,
00054 BEI_REQUEST_TYPE_FILLRECTANGLE,
00055 BEI_REQUEST_TYPE_FILLTRIANGLE,
00056 BEI_REQUEST_TYPE_DRAWLINE,
00057 BEI_REQUEST_TYPE_DRAWRECTANGLE,
00058 BEI_REQUEST_TYPE_DRAWTRIANGLE,
00059 BEI_REQUEST_TYPE_BLIT,
00060 BEI_REQUEST_TYPE_STRETCHBLIT,
00061 BEI_REQUEST_TYPE_STRETCHBLITBUFFER,
00062 BEI_REQUEST_TYPE_CREATEALPHATEXTURE,
00063 BEI_REQUEST_TYPE_DELETETEXTURE,
00064 BEI_REQUEST_TYPE_DRAWSTRING,
00065 BEI_REQUEST_TYPE_RENDERSCENE,
00066 BEI_REQUEST_TYPE_MERGE,
00067 BEI_REQUEST_TYPE_INITVERTEXBUFFER,
00068 BEI_REQUEST_TYPE_INITVERTEXSUBBUFFER,
00069 BEI_REQUEST_TYPE_INITINDEXBUFFER,
00070 BEI_REQUEST_TYPE_INITINDEXSUBBUFFER,
00071 BEI_REQUEST_TYPE_DELETEBUFFER
00072 } BEI_REQUEST_TYPE;
00073
00074 typedef struct {
00075 BEI_REQUEST_TYPE type;
00076 #ifdef __HAVE_XLIB__
00077 Display *x_display;
00078 int x_screen;
00079 Window x_window;
00080 MMSFBRectangle x11_win_rect;
00081 #endif
00082 } BEI_INIT;
00083
00084 typedef struct {
00085 BEI_REQUEST_TYPE type;
00086 } BEI_SWAP;
00087
00088 typedef struct {
00089 BEI_REQUEST_TYPE type;
00090 MMSFBSurface *surface;
00091 } BEI_ALLOC;
00092
00093 typedef struct {
00094 BEI_REQUEST_TYPE type;
00095 MMSFBSurface *surface;
00096 } BEI_FREE;
00097
00098 typedef struct {
00099 BEI_REQUEST_TYPE type;
00100 MMSFBSurface *surface;
00101 MMSFBColor color;
00102 } BEI_CLEAR;
00103
00104 typedef struct {
00105 BEI_REQUEST_TYPE type;
00106 MMSFBSurface *surface;
00107 MMSFBRectangle rect;
00108 MMSFBDrawingFlags drawingflags;
00109 } BEI_FILLRECTANGLE;
00110
00111 typedef struct {
00112 BEI_REQUEST_TYPE type;
00113 MMSFBSurface *surface;
00114 MMSFBTriangle triangle;
00115 } BEI_FILLTRIANGLE;
00116
00117 typedef struct {
00118 BEI_REQUEST_TYPE type;
00119 MMSFBSurface *surface;
00120 int x1;
00121 int y1;
00122 int x2;
00123 int y2;
00124 } BEI_DRAWLINE;
00125
00126 typedef struct {
00127 BEI_REQUEST_TYPE type;
00128 MMSFBSurface *surface;
00129 MMSFBRectangle rect;
00130 } BEI_DRAWRECTANGLE;
00131
00132 typedef struct {
00133 BEI_REQUEST_TYPE type;
00134 MMSFBSurface *surface;
00135 MMSFBTriangle triangle;
00136 } BEI_DRAWTRIANGLE;
00137
00138 typedef struct {
00139 BEI_REQUEST_TYPE type;
00140 MMSFBSurface *surface;
00141 MMSFBSurface *source;
00142 MMSFBRectangle src_rect;
00143 int x;
00144 int y;
00145 MMSFBBlittingFlags blittingflags;
00146 } BEI_BLIT;
00147
00148 typedef struct {
00149 BEI_REQUEST_TYPE type;
00150 MMSFBSurface *surface;
00151 MMSFBSurface *source;
00152 MMSFBRectangle src_rect;
00153 MMSFBRectangle dst_rect;
00154 MMSFBBlittingFlags blittingflags;
00155 } BEI_STRETCHBLIT;
00156
00157 typedef struct {
00158 BEI_REQUEST_TYPE type;
00159 MMSFBSurface *surface;
00160 MMSFBSurfacePlanes *src_planes;
00161 MMSFBSurfacePixelFormat src_pixelformat;
00162 int src_width;
00163 int src_height;
00164 MMSFBRectangle src_rect;
00165 MMSFBRectangle dst_rect;
00166 MMSFBBlittingFlags blittingflags;
00167 } BEI_STRETCHBLITBUFFER;
00168
00169 typedef struct {
00170 BEI_REQUEST_TYPE type;
00171 unsigned int *texture;
00172 unsigned char *buffer;
00173 int width;
00174 int height;
00175 } BEI_CREATEALPHATEXTURE;
00176
00177 typedef struct {
00178 BEI_REQUEST_TYPE type;
00179 unsigned int texture;
00180 } BEI_DELETETEXTURE;
00181
00182 typedef struct {
00183 BEI_REQUEST_TYPE type;
00184 MMSFBSurface *surface;
00185 string text;
00186 int len;
00187 int x;
00188 int y;
00189 } BEI_DRAWSTRING;
00190
00191 typedef struct {
00192 BEI_REQUEST_TYPE type;
00193 MMSFBSurface *surface;
00194 MMS_VERTEX_ARRAY **varrays;
00195 MMS_INDEX_ARRAY **iarrays;
00196 MMS3D_MATERIAL *materials;
00197 MMSFBSurface **texsurfaces;
00198 MMS3D_OBJECT **objects;
00199 } BEI_RENDERSCENE;
00200
00201 typedef struct {
00202 BEI_REQUEST_TYPE type;
00203 MMSFBSurface *surface;
00204 MMSFBSurface *source1;
00205 MMSFBSurface *source2;
00206 MMSFBMergingMode mergingmode;
00207 } BEI_MERGE;
00208
00209 typedef struct {
00210 BEI_REQUEST_TYPE type;
00211 unsigned int *buffer;
00212 unsigned int size;
00213 void *data;
00214 } BEI_INITVERTEXBUFFER;
00215
00216 typedef struct {
00217 BEI_REQUEST_TYPE type;
00218 unsigned int buffer;
00219 unsigned int offset;
00220 unsigned int size;
00221 void *data;
00222 } BEI_INITVERTEXSUBBUFFER;
00223
00224 typedef struct {
00225 BEI_REQUEST_TYPE type;
00226 unsigned int *buffer;
00227 unsigned int size;
00228 void *data;
00229 } BEI_INITINDEXBUFFER;
00230
00231 typedef struct {
00232 BEI_REQUEST_TYPE type;
00233 unsigned int buffer;
00234 unsigned int offset;
00235 unsigned int size;
00236 void *data;
00237 } BEI_INITINDEXSUBBUFFER;
00238
00239 typedef struct {
00240 BEI_REQUEST_TYPE type;
00241 unsigned int buffer;
00242 } BEI_DELETEBUFFER;
00243
00244 #ifdef __HAVE_OPENGL__
00245
00246
00247 MMSFBGL mmsfbgl;
00248
00249
00250 bool reset_matrix;
00251
00252
00253 bool matrix_central_projection;
00254
00255
00256 int matrix_left;
00257
00258
00259 int matrix_right;
00260
00261
00262 int matrix_bottom;
00263
00264
00265 int matrix_top;
00266
00267
00268 int matrix_nearZ;
00269
00270
00271 int matrix_farZ;
00272
00273
00274 void oglMatrix(bool central_projection, int left, int right, int bottom, int top, int nearZ = 0, int farZ = 1);
00275
00276
00277 void oglAlloc(MMSFBSurface *surface, bool rbo_required = false);
00278
00279
00280 void oglBindSurface(MMSFBSurface *surface);
00281
00282
00283 void oglBindSurface(MMSFBSurface *surface, int nearZ, int farZ, bool central_projection = false);
00284
00285
00286 bool oglDrawBuffer(MMSFBBuffer::BUFFER *buffer,
00287 MMSFBBuffer::INDEX_BUFFER *index_buffer = NULL,
00288 MMSFBBuffer::VERTEX_BUFFER *vertex_buffer = NULL);
00289
00290 #endif
00291
00292
00293 void processData(void *in_data, int in_data_len, void **out_data, int *out_data_len);
00294 void processInit(BEI_INIT *req);
00295 void processSwap(BEI_SWAP *req);
00296 void processAlloc(BEI_ALLOC *req);
00297 void processFree(BEI_FREE *req);
00298 void processClear(BEI_CLEAR *req);
00299 void processFillRectangle(BEI_FILLRECTANGLE *req);
00300 void processFillTriangle(BEI_FILLTRIANGLE *req);
00301 void processDrawLine(BEI_DRAWLINE *req);
00302 void processDrawRectangle(BEI_DRAWRECTANGLE *req);
00303 void processDrawTriangle(BEI_DRAWTRIANGLE *req);
00304 void processBlit(BEI_BLIT *req);
00305 void processStretchBlit(BEI_STRETCHBLIT *req);
00306 void processStretchBlitBuffer(BEI_STRETCHBLITBUFFER *req);
00307 void processCreateAlphaTexture(BEI_CREATEALPHATEXTURE *req);
00308 void processDeleteTexture(BEI_DELETETEXTURE *req);
00309 void processDrawString(BEI_DRAWSTRING *req);
00310 void processRenderScene(BEI_RENDERSCENE *req);
00311 void processMerge(BEI_MERGE *req);
00312 void processInitVertexBuffer(BEI_INITVERTEXBUFFER *req);
00313 void processInitVertexSubBuffer(BEI_INITVERTEXSUBBUFFER *req);
00314 void processInitIndexBuffer(BEI_INITINDEXBUFFER *req);
00315 void processInitIndexSubBuffer(BEI_INITINDEXSUBBUFFER *req);
00316 void processDeleteBuffer(BEI_DELETEBUFFER *req);
00317
00318 public:
00319
00320 MMSFBBackEndInterface(int queue_size = 1000);
00321
00322 #ifdef __HAVE_XLIB__
00323 void init(Display *x_display, int x_screen, Window x_window, MMSFBRectangle x11_win_rect);
00324 #endif
00325 void init();
00326
00327 void swap();
00328 void alloc(MMSFBSurface *surface);
00329 void free(MMSFBSurface *surface);
00330 void clear(MMSFBSurface *surface, MMSFBColor &color);
00331 void fillRectangle(MMSFBSurface *surface, MMSFBRectangle &rect, MMSFBDrawingFlags drawingflags);
00332 void fillTriangle(MMSFBSurface *surface, MMSFBTriangle &triangle);
00333 void drawLine(MMSFBSurface *surface, int x1, int y1, int x2, int y2);
00334 void drawRectangle(MMSFBSurface *surface, MMSFBRectangle &rect);
00335 void drawTriangle(MMSFBSurface *surface, MMSFBTriangle &triangle);
00336 void blit(MMSFBSurface *surface, MMSFBSurface *source, MMSFBRectangle &src_rect, int x, int y, MMSFBBlittingFlags blittingflags);
00337 void stretchBlit(MMSFBSurface *surface, MMSFBSurface *source, MMSFBRectangle &src_rect, MMSFBRectangle &dst_rect, MMSFBBlittingFlags blittingflags);
00338 void blitBuffer(MMSFBSurface *surface, MMSFBSurfacePlanes *src_planes, MMSFBSurfacePixelFormat src_pixelformat,
00339 int src_width, int src_height, MMSFBRectangle &src_rect, int x, int y, MMSFBBlittingFlags blittingflags);
00340 void stretchBlitBuffer(MMSFBSurface *surface, MMSFBSurfacePlanes *src_planes, MMSFBSurfacePixelFormat src_pixelformat,
00341 int src_width, int src_height, MMSFBRectangle &src_rect, MMSFBRectangle &dst_rect, MMSFBBlittingFlags blittingflags);
00342 void createAlphaTexture(unsigned int *texture, unsigned char *buffer, int width, int height);
00343 void deleteTexture(unsigned int texture);
00344 void drawString(MMSFBSurface *surface, string &text, int len, int x, int y);
00345 void renderScene(MMSFBSurface *surface,
00346 MMS_VERTEX_ARRAY **varrays,
00347 MMS_INDEX_ARRAY **iarrays,
00348 MMS3D_MATERIAL *materials,
00349 MMSFBSurface **texsurfaces,
00350 MMS3D_OBJECT **objects);
00351 void merge(MMSFBSurface *surface, MMSFBSurface *source1, MMSFBSurface *source2, MMSFBMergingMode mergingmode);
00352 void initVertexBuffer(unsigned int *buffer, unsigned int size, void *data = NULL);
00353 void initVertexSubBuffer(unsigned int buffer, unsigned int offset, unsigned int size, void *data);
00354 void initIndexBuffer(unsigned int *buffer, unsigned int size, void *data = NULL);
00355 void initIndexSubBuffer(unsigned int buffer, unsigned int offset, unsigned int size, void *data);
00356 void deleteBuffer(unsigned int buffer);
00357 };
00358
00359 #endif
00360
00361
00362
00363
00364