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

Side by Side Diff: src/gpu/gl/SkGLContext.cpp

Issue 12328111: Use glGetStringi to get extensions when available. (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
« no previous file with comments | « src/gpu/gl/GrGLUtil.cpp ('k') | src/gpu/gl/debug/GrGLCreateDebugInterface.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "gl/SkGLContext.h" 8 #include "gl/SkGLContext.h"
9 #include "gl/GrGLUtil.h" 9 #include "GrGLUtil.h"
10 10
11 SK_DEFINE_INST_COUNT(SkGLContext) 11 SK_DEFINE_INST_COUNT(SkGLContext)
12 12
13 SkGLContext::SkGLContext() 13 SkGLContext::SkGLContext()
14 : fFBO(0) 14 : fFBO(0)
15 , fColorBufferID(0) 15 , fColorBufferID(0)
16 , fDepthStencilBufferID(0) 16 , fDepthStencilBufferID(0)
17 , fGL(NULL) { 17 , fGL(NULL) {
18 } 18 }
19 19
20 SkGLContext::~SkGLContext() { 20 SkGLContext::~SkGLContext() {
21 21
22 if (fGL) { 22 if (fGL) {
23 // TODO: determine why DeleteFramebuffers is generating a GL error in te sts 23 // TODO: determine why DeleteFramebuffers is generating a GL error in te sts
24 SK_GL_NOERRCHECK(*this, DeleteFramebuffers(1, &fFBO)); 24 SK_GL_NOERRCHECK(*this, DeleteFramebuffers(1, &fFBO));
25 SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fColorBufferID)); 25 SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fColorBufferID));
26 SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fDepthStencilBufferID)); 26 SK_GL_NOERRCHECK(*this, DeleteRenderbuffers(1, &fDepthStencilBufferID));
27 } 27 }
28 28
29 SkSafeUnref(fGL); 29 SkSafeUnref(fGL);
30 } 30 }
31 31
32 bool SkGLContext::hasExtension(const char* extensionName) const {
33 return GrGLHasExtensionFromString(extensionName, fExtensionString.c_str());
34 }
35
36 bool SkGLContext::init(int width, int height) { 32 bool SkGLContext::init(int width, int height) {
37 if (fGL) { 33 if (fGL) {
38 fGL->unref(); 34 fGL->unref();
39 this->destroyGLContext(); 35 this->destroyGLContext();
40 } 36 }
41 37
42 fGL = this->createGLContext(); 38 fGL = this->createGLContext();
43 if (fGL) { 39 if (fGL) {
44 const GrGLubyte* temp; 40 const GrGLubyte* temp;
45 41
46 SK_GL_RET(*this, temp, GetString(GR_GL_EXTENSIONS)); 42 GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl());
47 fExtensionString = reinterpret_cast<const char*>(temp); 43
44 if (!fGL->validate(bindingInUse) || !fExtensions.init(bindingInUse, fGL) ) {
45 fGL = NULL;
46 this->destroyGLContext();
47 return false;
48 }
48 49
49 SK_GL_RET(*this, temp, GetString(GR_GL_VERSION)); 50 SK_GL_RET(*this, temp, GetString(GR_GL_VERSION));
50 const char* versionStr = reinterpret_cast<const char*>(temp); 51 const char* versionStr = reinterpret_cast<const char*>(temp);
51 GrGLVersion version = GrGLGetVersionFromString(versionStr); 52 GrGLVersion version = GrGLGetVersionFromString(versionStr);
52 53
53 // clear any existing GL erorrs 54 // clear any existing GL erorrs
54 GrGLenum error; 55 GrGLenum error;
55 do { 56 do {
56 SK_GL_RET(*this, error, GetError()); 57 SK_GL_RET(*this, error, GetError());
57 } while (GR_GL_NO_ERROR != error); 58 } while (GR_GL_NO_ERROR != error);
58 59
59 GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl());
60
61 SK_GL(*this, GenFramebuffers(1, &fFBO)); 60 SK_GL(*this, GenFramebuffers(1, &fFBO));
62 SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO)); 61 SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO));
63 SK_GL(*this, GenRenderbuffers(1, &fColorBufferID)); 62 SK_GL(*this, GenRenderbuffers(1, &fColorBufferID));
64 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID)); 63 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID));
65 if (kES2_GrGLBinding == bindingInUse) { 64 if (kES2_GrGLBinding == bindingInUse) {
66 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, 65 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
67 GR_GL_RGBA8, 66 GR_GL_RGBA8,
68 width, height)); 67 width, height));
69 } else { 68 } else {
70 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, 69 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
71 GR_GL_RGBA, 70 GR_GL_RGBA,
72 width, height)); 71 width, height));
73 } 72 }
74 SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, 73 SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
75 GR_GL_COLOR_ATTACHMENT0, 74 GR_GL_COLOR_ATTACHMENT0,
76 GR_GL_RENDERBUFFER, 75 GR_GL_RENDERBUFFER,
77 fColorBufferID)); 76 fColorBufferID));
78 SK_GL(*this, GenRenderbuffers(1, &fDepthStencilBufferID)); 77 SK_GL(*this, GenRenderbuffers(1, &fDepthStencilBufferID));
79 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fDepthStencilBufferID) ); 78 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fDepthStencilBufferID) );
80 79
81 // Some drivers that support packed depth stencil will only succeed 80 // Some drivers that support packed depth stencil will only succeed
82 // in binding a packed format an FBO. However, we can't rely on packed 81 // in binding a packed format an FBO. However, we can't rely on packed
83 // depth stencil being available. 82 // depth stencil being available.
84 bool supportsPackedDepthStencil; 83 bool supportsPackedDepthStencil;
85 if (kES2_GrGLBinding == bindingInUse) { 84 if (kES2_GrGLBinding == bindingInUse) {
86 supportsPackedDepthStencil = 85 supportsPackedDepthStencil = this->hasExtension("GL_OES_packed_depth _stencil");
87 this->hasExtension("GL_OES_packed_depth_stencil");
88 } else { 86 } else {
89 supportsPackedDepthStencil = version >= GR_GL_VER(3,0) || 87 supportsPackedDepthStencil = version >= GR_GL_VER(3,0) ||
90 this->hasExtension("GL_EXT_packed_depth_stencil") || 88 this->hasExtension("GL_EXT_packed_depth _stencil") ||
91 this->hasExtension("GL_ARB_framebuffer_object"); 89 this->hasExtension("GL_ARB_framebuffer_ object");
92 } 90 }
93 91
94 if (supportsPackedDepthStencil) { 92 if (supportsPackedDepthStencil) {
95 // ES2 requires sized internal formats for RenderbufferStorage 93 // ES2 requires sized internal formats for RenderbufferStorage
96 // On Desktop we let the driver decide. 94 // On Desktop we let the driver decide.
97 GrGLenum format = kES2_GrGLBinding == bindingInUse ? 95 GrGLenum format = kES2_GrGLBinding == bindingInUse ?
98 GR_GL_DEPTH24_STENCIL8 : 96 GR_GL_DEPTH24_STENCIL8 :
99 GR_GL_DEPTH_STENCIL; 97 GR_GL_DEPTH_STENCIL;
100 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, 98 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER,
101 format, 99 format,
(...skipping 30 matching lines...) Expand all
132 fGL->unref(); 130 fGL->unref();
133 fGL = NULL; 131 fGL = NULL;
134 this->destroyGLContext(); 132 this->destroyGLContext();
135 return false; 133 return false;
136 } else { 134 } else {
137 return true; 135 return true;
138 } 136 }
139 } 137 }
140 return false; 138 return false;
141 } 139 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLUtil.cpp ('k') | src/gpu/gl/debug/GrGLCreateDebugInterface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698