|
From: Keith W. <kw...@cs...> - 2004-07-13 21:47:06
|
On Tue, 13 Jul 2004, Joseph J. Strout wrote: > Q3MemoryStorage_New makes a Quesa object that wraps a buffer of > memory you provide, but it doesn't *own* that buffer -- you do. Okay, so that buffer is being using by Quesa though, so I can't delete it until I know Quesa won't need it anymore, right? I mean, that seems obvious, except that there are a number of situations where you have to dispose of stuff after temporarily using it, for example when you get a shader from a trimesh. You have to dispose it when you're done, but that doesn't kill the trimesh's shader, just some copy you got...which I find very strange, since altering the copy you get alters the trimesh's shader as well, so it kinda isn't a copy also. For example, in the following code, you have a trimeshdata. You get a shader, then a texture, then a mipmap, then an image. THEN, you ditch the shader and the texure and manipulate the image. So you are altering a shader that belongs to the trimeshdata (how else would this code actually change the rendered appearance of an object, which it does do quite nicely), but at the same time you have to delete the intermediate objects as if they DON'T belong to the trimeshdata object. I find it all somewhat confusing. TQ3SurfaceShaderObject shader; TQ3TextureObject texture; TQ3Mipmap mipMap; TQ3StorageObject image; unsigned char* pixels; Q3AttributeSet_Get(triMeshData->triMeshAttributeSet, kQ3AttributeTypeSurfaceShader, &shader); Q3TextureShader_GetTexture(shader, &texture); Q3MipmapTexture_GetMipmap(texture, &mipMap); image = mipMap.image; Q3Object_Dispose(shader); Q3Object_Dispose(texture); unsigned long validSize, bufferSize; Q3MemoryStorage_GetBuffer(image, &pixels, &validSize, &bufferSize); unsigned short* pixelsShortPtr = (unsigned short*)pixels; for (int i = 0; i < bufferSize / 2; i++) *pixelsShortPtr++ = 0; //Just for demo purposes //Set the pixel buffer for the trimesh Q3MemoryStorage_SetBuffer(image, pixels, validSize, bufferSize); Q3Object_Dispose(image); ________________________________________________________________________ Keith Wiley kw...@cs... http://www.unm.edu/~keithw http://www.mp3.com/KeithWiley "Yet mark his perfect self-contentment, and hence learn his lesson, that to be self-contented is to be vile and ignorant, and that to aspire is better than to be blindly and impotently happy." -- Edwin A. Abbott, Flatland ________________________________________________________________________ |