Glop.h revision 2ab95d780b023152556d9f8659de734ec7b55047
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> 26#include <SkXfermode.h> 27 28namespace android { 29namespace uirenderer { 30 31class Program; 32 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 */ 39enum VertexAttribFlags { 40 // NOTE: position attribute always enabled 41 kNone_Attrib = 0, 42 kTextureCoord_Attrib = 1 << 0, 43 kColor_Attrib = 1 << 1, 44 kAlpha_Attrib = 1 << 2, 45}; 46 47 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 57struct Glop { 58 struct FloatColor { 59 float a, r, g, b; 60 }; 61 62 Rect bounds; 63 64 /* 65 * Stores mesh - vertex and index data. 66 * 67 * buffer objects and void*s are mutually exclusive 68 * indices are optional, currently only GL_UNSIGNED_SHORT supported 69 */ 70 struct Mesh { 71 VertexAttribFlags vertexFlags; 72 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported 73 GLuint vertexBufferObject; 74 GLuint indexBufferObject; 75 const void* vertices; 76 const void* indices; 77 int vertexCount; 78 GLsizei stride; 79 } mesh; 80 81 struct Fill { 82 Program* program; 83 FloatColor color; 84 85 /* TODO 86 union shader { 87 //... 88 }; TODO 89 */ 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; 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; 104 bool fudgingOffset; 105 } transform; 106 107 struct Blend { 108 GLenum src; 109 GLenum dst; 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 123