Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1735)

Side by Side Diff: src/gpu/gl/GrGLVertexArray.h

Issue 12533007: Use vertex array objects on core profiles. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrGLVertexArray_DEFINED
9 #define GrGLVertexArray_DEFINED
10
11 #include "GrResource.h"
12 #include "gl/GrGLFunctions.h"
13
14 #include "SkTArray.h"
15
16 class GrGLVertexBuffer;
17 class GrGLIndexBuffer;
18 class GrGpuGL;
19
20 /**
21 * This sets and tracks the vertex attribute array state. It is used internally by GrGLVertexArray
22 * (below) but is separate because it is also used to track the state of vertex array object 0.
23 */
24 class GrGLAttribArrayState {
25 public:
26 explicit GrGLAttribArrayState(int arrayCount = 0) { this->resize(arrayCount) ; }
27
28 void resize(int newCount) {
29 fAttribArrays.resize_back(newCount);
30 for (int i = 0; i < newCount; ++i) {
31 fAttribArrays[i].invalidate();
32 }
33 }
34
35 /**
36 * This function enables and sets vertex attrib state for the specified attr ib index. It is
37 * assumed that the GrGLAttribArrayState is tracking the state of the curren tly bound vertex
38 * array object.
39 */
40 void set(const GrGpuGL*,
41 int index,
42 GrGLVertexBuffer*,
43 GrGLint size,
44 GrGLenum type,
45 GrGLboolean normalized,
46 GrGLsizei stride,
47 GrGLvoid* offset);
48
49 /**
50 * This function disables vertex attribs not present in the mask. It is assu med that the
51 * GrGLAttribArrayState is tracking the state of the currently bound vertex array object.
52 */
53 void disableUnusedAttribArrays(const GrGpuGL*, uint64_t usedAttribArrayMask) ;
54
55 void invalidate() {
56 int count = fAttribArrays.count();
57 for (int i = 0; i < count; ++i) {
58 fAttribArrays[i].invalidate();
59 }
60 }
61
62 void notifyVertexBufferDelete(GrGLuint id) {
63 int count = fAttribArrays.count();
64 for (int i = 0; i < count; ++i) {
65 if (id == fAttribArrays[i].fVertexBufferID) {
66 fAttribArrays[i].invalidate();
67 }
68 }
69 }
70
71 /**
72 * The number of attrib arrays that this object is configured to track.
73 */
74 int count() const { return fAttribArrays.count(); }
75
76 private:
77 struct AttribArray {
78 void invalidate() {
79 fEnableIsValid = false;
80 fAttribPointerIsValid = false;
81 }
82
83 bool fEnableIsValid;
84 bool fAttribPointerIsValid;
85 bool fEnabled;
86 GrGLuint fVertexBufferID;
87 GrGLint fSize;
88 GrGLenum fType;
89 GrGLboolean fNormalized;
90 GrGLsizei fStride;
91 GrGLvoid* fOffset;
92 };
93
94 SkSTArray<16, AttribArray, true> fAttribArrays;
95 };
96
robertphillips 2013/03/06 16:14:20 // comment?
robertphillips 2013/03/06 16:14:20 // comment?
bsalomon 2013/03/06 16:23:26 Done.
97 class GrGLVertexArray : public GrResource {
98 public:
99 GrGLVertexArray(GrGpuGL* gpu, GrGLint id, int attribCount);
100
101 /**
102 * Binds this vertex array. If the ID has been deleted or abandoned then NUL L is returned.
103 * Otherwise, the GrGLAttribArrayState that is tracking this vertex array's attrib bindings is
104 * returned.
105 */
106 GrGLAttribArrayState* bind();
107
108 /**
109 * This is a version of the above function that also binds an index buffer t o the vertex
110 * array object.
111 */
112 GrGLAttribArrayState* bindWithIndexBuffer(const GrGLIndexBuffer* indexBuffer );
113
114 void notifyIndexBufferDelete(GrGLuint bufferID);
115
116 void notifyVertexBufferDelete(GrGLuint id) {
117 fAttribArrays.notifyVertexBufferDelete(id);
118 }
119
120 GrGLuint arrayID() const { return fID; }
121
122 void invalidateCachedState();
123
124 virtual size_t sizeInBytes() const SK_OVERRIDE { return 0; }
125
126 protected:
127 virtual void onAbandon() SK_OVERRIDE;
128
129 virtual void onRelease() SK_OVERRIDE;
130
131 private:
132 GrGLuint fID;
133 GrGLAttribArrayState fAttribArrays;
134 GrGLuint fIndexBufferID;
robertphillips 2013/03/06 16:14:20 not a bool?
bsalomon 2013/03/06 16:23:26 Done.
135 GrGLint fIndexBufferIDIsValid;
136
137 typedef GrResource INHERITED;
138 };
139
140 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698