diff options
Diffstat (limited to 'graphics.h')
-rw-r--r-- | graphics.h | 65 |
1 files changed, 46 insertions, 19 deletions
@@ -2,10 +2,16 @@ typedef enum { ORTHOGRAPHIC, - PERSPECTIVE + PERSPECTIVE, } Projection; enum { + PPoint, + PLine, + PTriangle, +}; + +enum { LIGHT_POINT, LIGHT_DIRECTIONAL, LIGHT_SPOT, @@ -21,6 +27,7 @@ typedef struct Vertexattr Vertexattr; typedef struct Vertex Vertex; typedef struct LightSource LightSource; typedef struct Material Material; +typedef struct Primitive Primitive; typedef struct Model Model; typedef struct Entity Entity; typedef struct Scene Scene; @@ -29,6 +36,7 @@ typedef struct FSparams FSparams; typedef struct SUparams SUparams; typedef struct Shadertab Shadertab; typedef struct Renderer Renderer; +typedef struct Rendertime Rendertime; typedef struct Renderjob Renderjob; typedef struct Framebuf Framebuf; typedef struct Framebufctl Framebufctl; @@ -78,14 +86,13 @@ struct Vertex Point3 n; /* surface normal */ Color c; /* shading color */ Point2 uv; /* texture coordinate */ - OBJMaterial *mtl; + Material *mtl; + /* TODO it'd be neat to use a dynamic hash table instead */ Vertexattr *attrs; /* attributes (aka varyings) */ ulong nattrs; }; -typedef Vertex Triangle[3]; - struct LightSource { Point3 p; @@ -95,29 +102,36 @@ struct LightSource struct Material { + char *name; Color ambient; Color diffuse; Color specular; double shininess; + Memimage *diffusemap; +}; + +struct Primitive +{ + int type; + Vertex v[3]; + Material *mtl; }; struct Model { - OBJ *obj; + Primitive *prims; + ulong nprims; Memimage *tex; /* texture map */ Memimage *nor; /* normals map */ Material *materials; ulong nmaterials; - - /* cache of renderable elems */ - OBJElem **elems; - ulong nelems; }; struct Entity { RFrame3; Model *mdl; + Entity *prev, *next; }; @@ -128,6 +142,7 @@ struct Scene ulong nents; void (*addent)(Scene*, Entity*); + void (*delent)(Scene*, Entity*); }; /* shader params */ @@ -149,12 +164,10 @@ struct FSparams struct SUparams { Framebuf *fb; - int id; Memimage *frag; - Channel *donec; Renderjob *job; - Entity *entity; + Primitive *eb, *ee; uvlong uni_time; @@ -174,16 +187,22 @@ struct Renderer Channel *c; }; +struct Rendertime +{ + uvlong t0, t1; +}; + struct Renderjob { + Ref; Framebuf *fb; Scene *scene; Shadertab *shaders; Channel *donec; - ulong nrem; /* remaining entities to process */ - ulong lastid; - uvlong time0; + struct { + Rendertime R, E, Tn, Rn; /* renderer, entityproc, tilers, rasterizers */ + } times; Renderjob *next; }; @@ -191,21 +210,22 @@ struct Renderjob struct Framebuf { Memimage *cb; /* color buffer */ - double *zbuf; /* z/depth buffer */ - Lock zbuflk; + double *zb; /* z/depth buffer */ Rectangle r; }; struct Framebufctl { + Lock; Framebuf *fb[2]; /* double buffering */ uint idx; /* front buffer index */ - Lock swplk; void (*draw)(Framebufctl*, Image*); void (*memdraw)(Framebufctl*, Memimage*); void (*swap)(Framebufctl*); void (*reset)(Framebufctl*); + Framebuf *(*getfb)(Framebufctl*); + Framebuf *(*getbb)(Framebufctl*); }; struct Viewport @@ -215,6 +235,7 @@ struct Viewport void (*draw)(Viewport*, Image*); void (*memdraw)(Viewport*, Memimage*); + Framebuf *(*getfb)(Viewport*); }; struct Camera @@ -234,6 +255,11 @@ struct Camera uvlong min, avg, max, acc, n, v; uvlong nframes; } stats; + + struct { + Rendertime R[100], E[100], Tn[100], Rn[100]; + int cur; + } times; }; /* camera */ @@ -257,13 +283,14 @@ void perspective(Matrix3, double, double, double, double); void orthographic(Matrix3, double, double, double, double, double, double); /* scene */ -int refreshmodel(Model*); +int loadobjmodel(Model*, OBJ*); Model *newmodel(void); void delmodel(Model*); Entity *newentity(Model*); void delentity(Entity*); Scene *newscene(char*); void delscene(Scene*); +void clearscene(Scene*); /* vertex */ void addvattr(Vertex*, char*, int, void*); |