| 1 | #ifndef GX_H |
|---|
| 2 | #define GX_H |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | #include <glv.h> |
|---|
| 24 | #include "ovalue.h" |
|---|
| 25 | #include "res.h" |
|---|
| 26 | #include "res_font.h" |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | enum ResourceTypes |
|---|
| 30 | { |
|---|
| 31 | RES_TYPE_TEXTURE = 0, |
|---|
| 32 | RES_TYPE_DRAWLIST, |
|---|
| 33 | RES_TYPE_FONT, |
|---|
| 34 | RES_TYPE_COUNT |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | enum OImageFormat |
|---|
| 42 | { |
|---|
| 43 | OR_IMG_GRAY = 1, |
|---|
| 44 | OR_IMG_RGB, |
|---|
| 45 | OR_IMG_RGBA |
|---|
| 46 | }; |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | typedef struct |
|---|
| 50 | { |
|---|
| 51 | uint8_t format; |
|---|
| 52 | uint8_t depth; |
|---|
| 53 | uint16_t width; |
|---|
| 54 | uint16_t height; |
|---|
| 55 | uint16_t _pad; |
|---|
| 56 | } |
|---|
| 57 | OImage; |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | typedef struct |
|---|
| 64 | { |
|---|
| 65 | Resource res; |
|---|
| 66 | |
|---|
| 67 | OIndex imgHold; |
|---|
| 68 | GLuint glTexId; |
|---|
| 69 | } |
|---|
| 70 | TextureResource; |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | enum RenderState |
|---|
| 77 | { |
|---|
| 78 | GRS_UNSET = 0, |
|---|
| 79 | GRS_TEXT, |
|---|
| 80 | GRS_SOLID, |
|---|
| 81 | GRS_MODEL |
|---|
| 82 | }; |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | struct GxRenderState |
|---|
| 86 | { |
|---|
| 87 | int stateId; |
|---|
| 88 | uint32_t fontKey; |
|---|
| 89 | GLfloat penX; |
|---|
| 90 | GLfloat penY; |
|---|
| 91 | |
|---|
| 92 | GLbitfield clear; |
|---|
| 93 | |
|---|
| 94 | OValue* vertVals; |
|---|
| 95 | OValue* normVals; |
|---|
| 96 | OValue* colorVals; |
|---|
| 97 | OValue* uvVals; |
|---|
| 98 | }; |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | struct GxEnv |
|---|
| 102 | { |
|---|
| 103 | double view_wd; |
|---|
| 104 | double view_hd; |
|---|
| 105 | double view_aspect; |
|---|
| 106 | |
|---|
| 107 | OAtom atom_joystick; |
|---|
| 108 | OAtom atom_model; |
|---|
| 109 | OAtom atom_solid; |
|---|
| 110 | |
|---|
| 111 | OContext input_ctx; |
|---|
| 112 | OValue* input_values; |
|---|
| 113 | |
|---|
| 114 | OIndex widgetCtxN; |
|---|
| 115 | OIndex drawListDialectBlkN; |
|---|
| 116 | |
|---|
| 117 | int prev_mouseX; |
|---|
| 118 | int prev_mouseY; |
|---|
| 119 | |
|---|
| 120 | int running; |
|---|
| 121 | struct GxRenderState state; |
|---|
| 122 | |
|---|
| 123 | ResourceDict resd; |
|---|
| 124 | }; |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | extern struct GxEnv gEnv; |
|---|
| 128 | extern GLView* gView; |
|---|
| 129 | extern const char* orAtomCString( OAtom atom ); |
|---|
| 130 | |
|---|
| 131 | extern void gxInitEnv(); |
|---|
| 132 | extern void gxFreeEnv(); |
|---|
| 133 | extern Resource* gxFindResource( int type, const char* name, int len ); |
|---|
| 134 | extern Resource* gxFindResourceKey( int type, uint32_t key ); |
|---|
| 135 | extern uint32_t gxHashString( OValue* ); |
|---|
| 136 | extern TextureResource* gxTexture( const char* file ); |
|---|
| 137 | extern void gxDrawText( FontResource*, const char* it, const char* end ); |
|---|
| 138 | extern void gxDrawTextValue( FontResource*, OValue* ); |
|---|
| 139 | extern GLuint gxLoadTexture( OValue* ); |
|---|
| 140 | |
|---|
| 141 | #define gxTexture(k) (TextureResource*) gxFindResourceKey(RES_TYPE_TEXTURE,k) |
|---|
| 142 | #define gxFont(k) (FontResource*) gxFindResourceKey(RES_TYPE_FONT,k) |
|---|
| 143 | #define gxDList(k) (DrawListResource*) gxFindResourceKey(RES_TYPE_DRAWLIST,k) |
|---|
| 144 | |
|---|
| 145 | #define gxSetPen(x,y) gEnv.state.penX = x; gEnv.state.penY = y |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | #define gxResultRES(rp) \ |
|---|
| 149 | {orSetTF(a1, OT_RESOURCE); \ |
|---|
| 150 | a1->argc = rp->res.resType; \ |
|---|
| 151 | a1->index = rp->res.resKey;} |
|---|
| 152 | |
|---|
| 153 | #define gxResType(val) val->argc |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | OBinary* orMakeImage( int format, int w, int h ); |
|---|
| 157 | |
|---|
| 158 | #define orImagePixels(bin) (bin->byteArray + sizeof(OImage)) |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | #endif |
|---|