X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fcmesh.c;h=6cf9b31f1e0a2ab75c17af5c95acc24d5e50aa66;hb=81ba28d6379707c51aa82e9fa75f42843c7a751f;hp=4d7425182bcd080250745f0d5188db6060bda0fc;hpb=1b62e1cf0e1cf019b42ee232ba838d06c55b8cda;p=vrtris diff --git a/src/cmesh.c b/src/cmesh.c index 4d74251..6cf9b31 100644 --- a/src/cmesh.c +++ b/src/cmesh.c @@ -49,6 +49,7 @@ static void update_wire_ibo(struct cmesh *cm); static void calc_aabb(struct cmesh *cm); static void calc_bsph(struct cmesh *cm); +static int def_nelem[CMESH_NUM_ATTR] = {3, 3, 3, 2, 4, 4, 4, 2}; static int sdr_loc[CMESH_NUM_ATTR] = {0, 1, 2, 3, 4, 5, 6, 7}; static int use_custom_sdr_attr; @@ -366,6 +367,70 @@ int cmesh_attrib_count(struct cmesh *cm, int attr) return cmesh_has_attrib(cm, attr) ? cm->nverts : 0; } +int cmesh_push_attrib(struct cmesh *cm, int attr, float *v) +{ + float *vptr; + int i; + int cursz = dynarr_size(cm->vattr[attr].data); + int newsz = cursz + cm->vattr[attr].nelem; + + if(!(vptr = dynarr_resize(cm->vattr[attr].data, newsz))) { + return -1; + } + cm->vattr[attr].data = vptr; + vptr += cursz; + + if(!cm->vattr[attr].nelem) { + cm->vattr[attr].nelem = def_nelem[attr]; + } + + for(i=0; ivattr[attr].nelem; i++) { + *vptr++ = *v++; + } + cm->vattr[attr].data_valid = 1; + cm->vattr[attr].vbo_valid = 0; + return 0; +} + +int cmesh_push_attrib1f(struct cmesh *cm, int attr, float x) +{ + float v[4]; + v[0] = x; + v[1] = v[2] = 0.0f; + v[3] = 1.0f; + return cmesh_push_attrib(cm, attr, v); +} + +int cmesh_push_attrib2f(struct cmesh *cm, int attr, float x, float y) +{ + float v[4]; + v[0] = x; + v[1] = y; + v[2] = 0.0f; + v[3] = 1.0f; + return cmesh_push_attrib(cm, attr, v); +} + +int cmesh_push_attrib3f(struct cmesh *cm, int attr, float x, float y, float z) +{ + float v[4]; + v[0] = x; + v[1] = y; + v[2] = z; + v[3] = 1.0f; + return cmesh_push_attrib(cm, attr, v); +} + +int cmesh_push_attrib4f(struct cmesh *cm, int attr, float x, float y, float z, float w) +{ + float v[4]; + v[0] = x; + v[1] = y; + v[2] = z; + v[3] = w; + return cmesh_push_attrib(cm, attr, v); +} + /* indices can be 0, in which case only memory is allocated * returns pointer to the index array */ @@ -435,6 +500,18 @@ int cmesh_index_count(struct cmesh *cm) return cm->nfaces * 3; } +int cmesh_push_index(struct cmesh *cm, unsigned int idx) +{ + unsigned int *iptr; + if(!(iptr = dynarr_push(cm->idata, &idx))) { + return -1; + } + cm->idata = iptr; + cm->idata_valid = 1; + cm->ibo_valid = 0; + return 0; +} + int cmesh_poly_count(struct cmesh *cm) { if(cm->nfaces) {