blob: 9150869884c58801224aa4e8c1028d91b1bae63d [file] [log] [blame]
Chris Craik6c15ffa2015-02-02 13:50:55 -08001/*
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 Craik03188872015-02-02 18:39:33 -080026#include <SkXfermode.h>
Chris Craik6c15ffa2015-02-02 13:50:55 -080027
28namespace android {
29namespace uirenderer {
30
Chris Craik03188872015-02-02 18:39:33 -080031class Program;
32
Chris Craik6c15ffa2015-02-02 13:50:55 -080033/*
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
Chris Craik117bdbc2015-02-05 10:12:38 -080041 kNone_Attrib = 0,
Chris Craik6c15ffa2015-02-02 13:50:55 -080042 kTextureCoord_Attrib = 1 << 0,
43 kColor_Attrib = 1 << 1,
44 kAlpha_Attrib = 1 << 2,
45};
46
Chris Craik117bdbc2015-02-05 10:12:38 -080047
Chris Craik6c15ffa2015-02-02 13:50:55 -080048/**
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 {
Chris Craik117bdbc2015-02-05 10:12:38 -080058 struct FloatColor {
59 float a, r, g, b;
60 };
61
Chris Craik6c15ffa2015-02-02 13:50:55 -080062 Rect bounds;
63
Chris Craik117bdbc2015-02-05 10:12:38 -080064 /*
65 * Stores mesh - vertex and index data.
66 *
67 * buffer objects and void*s are mutually exclusive
68 * indices are optional
69 */
Chris Craik6c15ffa2015-02-02 13:50:55 -080070 struct Mesh {
Chris Craik03188872015-02-02 18:39:33 -080071 VertexAttribFlags vertexFlags;
Chris Craik6c15ffa2015-02-02 13:50:55 -080072 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported
Chris Craik03188872015-02-02 18:39:33 -080073 GLuint vertexBufferObject;
74 GLuint indexBufferObject;
Chris Craik117bdbc2015-02-05 10:12:38 -080075 const void* vertices;
76 const void* indices;
Chris Craik6c15ffa2015-02-02 13:50:55 -080077 int vertexCount;
78 GLsizei stride;
79 } mesh;
80
81 struct Fill {
82 Program* program;
Chris Craik117bdbc2015-02-05 10:12:38 -080083 FloatColor color;
Chris Craik6c15ffa2015-02-02 13:50:55 -080084
85 /* TODO
86 union shader {
87 //...
88 }; TODO
Chris Craik6c15ffa2015-02-02 13:50:55 -080089 */
Chris Craik117bdbc2015-02-05 10:12:38 -080090 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 Craik6c15ffa2015-02-02 13:50:55 -080098 } 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 Craik117bdbc2015-02-05 10:12:38 -0800104 bool fudgingOffset;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800105 } transform;
106
107 struct Blend {
Chris Craik03188872015-02-02 18:39:33 -0800108 GLenum src;
109 GLenum dst;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800110 } 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