kivy / kivent

KivEnt is an entity-based game engine for Kivy
http://www.kivent.org
572 stars 94 forks source link

Dynamic Polygon Support #27

Open chozabu opened 10 years ago

chozabu commented 10 years ago

I am interested in polygons that can move and change color rapidly. As we have discussed, methods could include:

  1. Calling glTranslate and glRotate between polygons (color could also be done with glColor?)
  2. Using the VertexShader and uniform vars, changing them before drawing polygons
  3. Using the existing Vertex attribs, updating as needed in an speedy manner.
chozabu commented 10 years ago

I am currently in favor of (1 or 2) and 3 ;)

Kovak commented 10 years ago

Hey chozabu,

I wanted to put down my thoughts for how to go about expanding this portion.

The main problem is that the current system was designed for static meshes. In order to introduce dynamic vertices we need to introduce several types of modifcations.

Handling Modification of Vertex Attributes

  1. Direct modification of each vertex's properties. There is something like this right now with the offset_mesh function. This takes a single tuple of x, y from python and moves the whole mesh by this. This is somewhat ideal because we have little input from python and afterwards most everything can be handled in python. However, it is restricted by assuming v0, v1 of each vertex is the x, y position. We need a dynamic alternative that allows the user to modify any of the vertices in this manner from python.
  2. We need a way to modify many vertices in individual ways. This is somewhat rough because to be used from python there will be a lot of unpacking python objects into Cython. It will end up looking similar to the way mesh's are constructed from lists at the moment. However, there is a good chance this will be a fairly slow process and unideal.

Modification at the Canvas Level

  1. This would be things like using Kivy's Color, Translate, and Rotate functions. We would need to modify the existing shaders to take into account the canvas projection and modelview matrices. This would require encasing the individual Mesh drawing instructions in Push/Pop matrix, but as long as the user does not try to render 100s of meshes I think this will not be too bad. This method would not work with any batching that we may want later.

One of the fundamental problems here is that we have access to per vertex attributes which can be controlled at the vertex level but require many data points to be duplicated if shared between vertices, and uniform attributes which will be the same per canvas and thus shared between every mesh rendered. Apple makes reference to GL ES 2.0 having some type of Constant Vertex Attribute we could set manually with a gl command, but I can't find much documentation on it https://developer.apple.com/library/ios/documentation/3ddrawing/conceptual/opengles_programmingguide/TechniquesforWorkingwithVertexData/TechniquesforWorkingwithVertexData.html