X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrtris;a=blobdiff_plain;f=src%2Fcmesh.c;h=31905761ac1e37f082d4d8411cdd46fa6c3fee39;hp=4d7425182bcd080250745f0d5188db6060bda0fc;hb=06a83976694c970fcf42bfdfc91832e780ca4747;hpb=1b62e1cf0e1cf019b42ee232ba838d06c55b8cda diff --git a/src/cmesh.c b/src/cmesh.c index 4d74251..3190576 100644 --- a/src/cmesh.c +++ b/src/cmesh.c @@ -366,6 +366,64 @@ 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; + for(i=0; ivattr[attr].nelem; i++) { + *vptr++ = *v++; + } + 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 +493,16 @@ 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; + return 0; +} + int cmesh_poly_count(struct cmesh *cm) { if(cm->nfaces) {