RE: Core Data OpenGL
RE: Core Data OpenGL
- Subject: RE: Core Data OpenGL
- From: Erik Buck <email@hidden>
- Date: Thu, 22 Feb 2007 07:49:01 -0800 (PST)
I use Core Data to store textures as NSData, large point meshes as NSData, colors as RGBA float attributes, scene graph information as a graph of Core Data entities, etc.
I have not found that Core Data is particularly unsuited to 3D OpenGL systems.
Think about it this way: OpenGL should be constrained to the View layer when using Model/View/Controller (MVC). Core Data is constrained to representing the Model. There is no coupling between the Model and the View, so it shouldn't matter how you represent the Model when using OpenGL. Furthermore, the same Core Data model should work fine with other View layers such as DirectX or ray-trace renderers etc.
As it happens, meshes and textures etc. end up cached in the Graphics card. Reading such data from Core Data may not provide optimal performance, but who cares ? You only read the model once and convert to OpenGL Vertex Arrays and Core Image Textures etc. You never need to touch the Core Data Model again until something changes in the Model, and frankly, re-caching and redrawing in the graphics card will take a lot longer than modifying the Core data entities.
For example, I have a 3D Mesh editor. Each time the user interactively changes a mesh and particularly when points are added or removed from a mesh, I update the OpenGL Vertex Buffer or Display List which takes up to ~400ms to change and redisplay on my test machine. (it is computationally expensive sometimes) I also copy the updated mesh as an NSData attribute of an scene graph entity which only takes ~1ms. The user is not going to notice the "extra" work of using Core Data, but the user does notice the built-in undo/redo and other advantages that come for free when using Core Data.
After a mesh is edited (including texture coordinates for multiple textures), users can also interactively draw on the texture in 3D. Because the Core Image textures are stored using Core Data, the user also gets undo/redo of texture painting and related operations.
IMHO, Core Data adds negligible overhead and data conversion hassles in exchange for very valuable built-in features. Ironically, the fact that OpenGL is best used when NOT in "immediate" mode makes Core Data MORE suitable as a Model than it would be in an interactive 2D Quartz drawing/animation system that needs to read Core Data entities/attributes more often.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden