Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ANDROID_HWUI_GLOP_H |
| 18 | #define ANDROID_HWUI_GLOP_H |
| 19 | |
| 20 | #include "Matrix.h" |
| 21 | #include "Rect.h" |
| 22 | #include "utils/Macros.h" |
| 23 | |
| 24 | #include <GLES2/gl2.h> |
| 25 | #include <GLES2/gl2ext.h> |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 26 | #include <SkXfermode.h> |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 31 | class Program; |
| 32 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 33 | /* |
| 34 | * Enumerates optional vertex attributes |
| 35 | * |
| 36 | * Position is always enabled by MeshState, these other attributes |
| 37 | * are enabled/disabled dynamically based on mesh content. |
| 38 | */ |
| 39 | enum VertexAttribFlags { |
| 40 | // NOTE: position attribute always enabled |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 41 | kNone_Attrib = 0, |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 42 | kTextureCoord_Attrib = 1 << 0, |
| 43 | kColor_Attrib = 1 << 1, |
| 44 | kAlpha_Attrib = 1 << 2, |
| 45 | }; |
| 46 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 47 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 48 | /** |
| 49 | * Structure containing all data required to issue a single OpenGL draw |
| 50 | * |
| 51 | * Includes all of the mesh, fill, and GL state required to perform |
| 52 | * the operation. Pieces of data are either directly copied into the |
| 53 | * structure, or stored as a pointer or GL object reference to data |
| 54 | * managed |
| 55 | */ |
| 56 | // TODO: PREVENT_COPY_AND_ASSIGN(...) or similar |
| 57 | struct Glop { |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 58 | struct FloatColor { |
| 59 | float a, r, g, b; |
| 60 | }; |
| 61 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 62 | Rect bounds; |
| 63 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 64 | /* |
| 65 | * Stores mesh - vertex and index data. |
| 66 | * |
| 67 | * buffer objects and void*s are mutually exclusive |
Chris Craik | 2ab95d7 | 2015-02-06 15:25:51 -0800 | [diff] [blame] | 68 | * indices are optional, currently only GL_UNSIGNED_SHORT supported |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 69 | */ |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 70 | struct Mesh { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 71 | VertexAttribFlags vertexFlags; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 72 | GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 73 | GLuint vertexBufferObject; |
| 74 | GLuint indexBufferObject; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 75 | const void* vertices; |
| 76 | const void* indices; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 77 | int vertexCount; |
| 78 | GLsizei stride; |
| 79 | } mesh; |
| 80 | |
| 81 | struct Fill { |
| 82 | Program* program; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 83 | FloatColor color; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 84 | |
| 85 | /* TODO |
| 86 | union shader { |
| 87 | //... |
| 88 | }; TODO |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 89 | */ |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 90 | ProgramDescription::ColorFilterMode filterMode; |
| 91 | union Filter { |
| 92 | struct Matrix { |
| 93 | float matrix[16]; |
| 94 | float vector[4]; |
| 95 | } matrix; |
| 96 | FloatColor color; |
| 97 | } filter; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 98 | } fill; |
| 99 | |
| 100 | struct Transform { |
| 101 | Matrix4 ortho; // TODO: out of op, since this is static per FBO |
| 102 | Matrix4 modelView; |
| 103 | Matrix4 canvas; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 104 | bool fudgingOffset; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 105 | } transform; |
| 106 | |
| 107 | struct Blend { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 108 | GLenum src; |
| 109 | GLenum dst; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 110 | } blend; |
| 111 | |
| 112 | /** |
| 113 | * Additional render state to enumerate: |
| 114 | * - scissor + (bits for whether each of LTRB needed?) |
| 115 | * - stencil mode (draw into, mask, count, etc) |
| 116 | */ |
| 117 | }; |
| 118 | |
| 119 | } /* namespace uirenderer */ |
| 120 | } /* namespace android */ |
| 121 | |
| 122 | #endif // ANDROID_HWUI_GLOP_H |