clcopy.c

00001 #include <cl.h>
00002 
00006 CLcolour* clCopyColour(CLcolour* dest, const CLcolour* src)
00007 {
00008     return (CLcolour*)CL_MEMCPY(dest, src, sizeof(CLcolour));
00009 }
00010 
00011 CLvertex* clCopyVertex(CLvertex* dest, const CLvertex* src)
00012 {
00013     return (CLvertex*)CL_MEMCPY(dest, src, sizeof(CLvertex));
00014 }
00015 
00016 CLnormal* clCopyNormal(CLnormal* dest, const CLnormal* src)
00017 {
00018     return (CLnormal*)CL_MEMCPY(dest, src, sizeof(CLnormal));
00019 }
00020 
00021 CLtexcoord* clCopyTexCoord(CLtexcoord* dest, const CLtexcoord* src)
00022 {
00023     return (CLtexcoord*)CL_MEMCPY(dest, src, sizeof(CLtexcoord));
00024 }
00025 
00026 CLedgeflag* clCopyEdgeFlag(CLedgeflag* dest, const CLedgeflag* src)
00027 {
00028     return (CLedgeflag*)CL_MEMCPY(dest, src, sizeof(CLedgeflag));
00029 }
00030 
00031 CLmatrix* clCopyMatrix(CLmatrix* dest, const CLmatrix* src)
00032 {
00033     return (CLmatrix*)CL_MEMCPY(dest, src, sizeof(CLmatrix));
00034 }
00035 
00036 CLimage* clCopyImage(CLimage* dest, const CLimage* src)
00037 {
00038     GLuint image_data_size;
00039     
00040     if (!(dest && src))
00041     {   
00042         return 0;
00043     }
00044     
00045     clClearImage(dest);
00046     
00047     dest = (CLimage*)memcpy(dest, src, sizeof(CLimage));
00048     
00049     image_data_size = clImageDataSize(dest);
00050     
00051     dest->data = (GLvoid*)CL_MALLOC(image_data_size);
00052     dest->data = (GLvoid*)CL_MEMCPY(dest->data, src->data, image_data_size);
00053     
00054     return dest;
00055 }
00056 
00060 CLlight* clCopyLight(CLlight* dest, const CLlight* src)
00061 {
00062   if (!(dest && src))
00063   {
00064       return 0;
00065   }
00066 
00067   clClearLight(dest);
00068 
00069   dest = (CLlight*)memcpy(dest, src, sizeof(CLlight));
00070   
00071   dest->display_list = 0;
00072 
00073   return dest;
00074 }
00075 
00079 CLmaterial* clCopyMaterial(CLmaterial* dest, const CLmaterial* src)
00080 {
00081   if (!(dest && src))
00082   {
00083       return 0;
00084   }
00085   
00086   clClearMaterial(dest);
00087 
00088   dest = (CLmaterial*)memcpy(dest, src, sizeof(CLmaterial));
00089 
00090   dest->display_list = 0;
00091 
00092   return dest;
00093 }
00094 
00098 CLtexture* clCopyTexture(CLtexture* dest, const CLtexture* src)
00099 {
00100   if (!(dest && src))
00101   {
00102       return 0;
00103   }
00104 
00105   clClearTexture(dest);
00106 
00107   dest = (CLtexture*)memcpy(dest, src, sizeof(CLtexture));
00108 
00109   clCopyImage(&dest->image, &src->image);
00110   
00111   dest->texture_object = 0;
00112 
00113   return dest;
00114 }
00115 
00116 CLprimitiveset* clCopyPrimitiveSet(CLprimitiveset* dest, const CLprimitiveset* src)
00117 {
00118   if (!(dest && src))
00119   {
00120       return 0;
00121   }
00122   
00123   clClearPrimitiveSet(dest);
00124 
00125   dest = (CLprimitiveset*)memcpy(dest, src, sizeof(CLprimitiveset));
00126   
00127   dest->indices = (GLuint*)CL_MALLOC(dest->num_indices * sizeof(GLuint));
00128   dest->indices = (GLuint*)CL_MEMCPY(dest->indices, src->indices, 
00129                                       dest->num_indices * sizeof(GLuint));
00130 
00131   return dest;
00132 }
00133 
00137 CLmesh* clCopyMesh(CLmesh* dest, const CLmesh* src)
00138 {
00139     unsigned int i;
00140 
00141     if (!(dest && src))
00142     {
00143         return 0;
00144     }
00145     
00146     clClearMesh(dest);
00147     
00148     dest = (CLmesh*)memcpy(dest, src, sizeof(CLmesh));
00149     
00150     if (src->colour)
00151     {
00152         dest->colour = clCopyColour(clNewColour(), src->colour);
00153     }
00154     
00155     dest->vertices = (CLvertex*)CL_MALLOC(dest->num_vertices 
00156                                           * sizeof(CLvertex));
00157     dest->vertices = (CLvertex*)CL_MEMCPY(dest->vertices,
00158                                           src->vertices, 
00159                                           dest->num_vertices * sizeof(CLvertex));
00160     
00161     dest->colours = (CLcolour*)CL_MALLOC(dest->num_vertices
00162                                          * sizeof(CLcolour));
00163     dest->colours = (CLcolour*)CL_MEMCPY(dest->colours,
00164                                          src->colours, 
00165                                          dest->num_vertices * sizeof(CLcolour));
00166     
00167     dest->normals = (CLnormal*)CL_MALLOC(dest->num_vertices
00168                                          * sizeof(CLnormal));
00169     dest->normals = (CLnormal*)CL_MEMCPY(dest->normals,
00170                                          src->normals, 
00171                                          dest->num_vertices * sizeof(CLnormal));
00172     
00173     dest->texcoords = (CLtexcoord*)CL_MALLOC(dest->num_vertices 
00174                                              * sizeof(CLtexcoord));
00175     dest->texcoords = (CLtexcoord*)CL_MEMCPY(dest->texcoords,
00176                                              src->texcoords, 
00177                                              dest->num_vertices * sizeof(CLtexcoord));
00178     
00179     dest->edgeflags = (CLedgeflag*)CL_MALLOC(dest->num_vertices 
00180                                              * sizeof(CLedgeflag));
00181     dest->edgeflags = (CLedgeflag*)CL_MEMCPY(dest->edgeflags,
00182                                              src->edgeflags, 
00183                                              dest->num_vertices * sizeof(CLcolour));
00184     
00185     dest->primitivesets = (CLprimitiveset**)CL_MALLOC(dest->num_primitivesets
00186                                                       * sizeof(CLprimitiveset*));
00187     
00188     for (i = 0; i < dest->num_primitivesets; i++)
00189     {
00190         dest->primitivesets[i] = clCopyPrimitiveSet(clNewPrimitiveSet(), 
00191                                                     src->primitivesets[i]);
00192     }
00193     
00194     dest->display_list = 0;
00195     
00196     return dest;
00197 }
00198 
00200 CLcontext* clCopyContext(CLcontext* dest, const CLcontext* src)
00201 {
00202     unsigned int i;
00203 
00204     if (!(dest && src))
00205     {
00206         return 0;
00207     }
00208     
00209     clClearContext(dest);
00210     
00211     dest = clNewContext();
00212     
00213     dest->num_materials = src->num_materials;
00214     dest->materials = (CLmaterial**)CL_MALLOC(dest->num_materials
00215                                               * sizeof(CLmaterial*));
00216     for (i = 0; i < dest->num_materials; i++)
00217     {
00218         dest->materials[i] = clCopyMaterial(clNewMaterial(), src->materials[i]);
00219     }
00220     
00221     dest->num_textures = src->num_textures;
00222     dest->textures = (CLtexture**)CL_MALLOC(dest->num_textures
00223                                             * sizeof(CLtexture*));
00224     for (i = 0; i < dest->num_textures; i++)
00225     {
00226         dest->textures[i] = clCopyTexture(clNewTexture(), src->textures[i]);
00227     }
00228     
00229     dest->num_lights = src->num_lights;
00230     dest->lights = (CLlight**)CL_MALLOC(dest->num_lights * sizeof(CLlight*));
00231     for (i = 0; i < dest->num_lights; i++)
00232     {
00233         dest->lights[i] = clCopyLight(clNewLight(), src->lights[i]);
00234     }
00235     
00236     dest->num_models = src->num_models;
00237     dest->models = (CLmodel**)CL_MALLOC(dest->num_models * sizeof(CLmodel*));
00238     for (i = 0; i < dest->num_models; i++)
00239     {
00240         dest->models[i] = clCopyModel(clNewModel(), src->models[i]);
00241     }
00242     
00243     return dest;
00244 }
00245 
00246 CLmodel* clCopyModel(CLmodel* dest, const CLmodel* src)
00247 {
00248     unsigned int i;
00249     
00250     if (!(dest && src))
00251     {
00252         return 0;
00253     }
00254     
00255     clClearModel(dest);
00256     
00257     dest = (CLmodel*)memcpy(dest, src, sizeof(CLmodel));
00258     
00259     dest->meshes = (CLmesh**)CL_MALLOC(dest->num_meshes * sizeof(CLmesh*));
00260     for (i = 0; i < dest->num_meshes; i++)
00261     {
00262         dest->meshes[i] = clCopyMesh(clNewMesh(), src->meshes[i]);
00263     }
00264     
00265     return dest;
00266 }

Generated on Thu Dec 27 13:53:41 2007 for CL by  doxygen 1.4.6