OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 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/SkGLContextHelper.h" | 8 #include "gl/SkGLContextHelper.h" |
9 #include "GrGLUtil.h" | 9 #include "GrGLUtil.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 bool SkGLContextHelper::init(int width, int height) { | 30 bool SkGLContextHelper::init(int width, int height) { |
31 if (fGL) { | 31 if (fGL) { |
32 fGL->unref(); | 32 fGL->unref(); |
33 this->destroyGLContext(); | 33 this->destroyGLContext(); |
34 } | 34 } |
35 | 35 |
36 fGL = this->createGLContext(); | 36 fGL = this->createGLContext(); |
37 if (fGL) { | 37 if (fGL) { |
38 const GrGLubyte* temp; | 38 const GrGLubyte* temp; |
39 | 39 |
40 GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl()); | 40 if (!fGL->validate() || !fExtensions.init(fGL)) { |
41 | |
42 if (!fGL->validate(bindingInUse) || !fExtensions.init(bindingInUse, fGL)
) { | |
43 fGL = NULL; | 41 fGL = NULL; |
44 this->destroyGLContext(); | 42 this->destroyGLContext(); |
45 return false; | 43 return false; |
46 } | 44 } |
47 | 45 |
48 SK_GL_RET(*this, temp, GetString(GR_GL_VERSION)); | 46 SK_GL_RET(*this, temp, GetString(GR_GL_VERSION)); |
49 const char* versionStr = reinterpret_cast<const char*>(temp); | 47 const char* versionStr = reinterpret_cast<const char*>(temp); |
50 GrGLVersion version = GrGLGetVersionFromString(versionStr); | 48 GrGLVersion version = GrGLGetVersionFromString(versionStr); |
51 | 49 |
52 // clear any existing GL erorrs | 50 // clear any existing GL erorrs |
53 GrGLenum error; | 51 GrGLenum error; |
54 do { | 52 do { |
55 SK_GL_RET(*this, error, GetError()); | 53 SK_GL_RET(*this, error, GetError()); |
56 } while (GR_GL_NO_ERROR != error); | 54 } while (GR_GL_NO_ERROR != error); |
57 | 55 |
58 SK_GL(*this, GenFramebuffers(1, &fFBO)); | 56 SK_GL(*this, GenFramebuffers(1, &fFBO)); |
59 SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO)); | 57 SK_GL(*this, BindFramebuffer(GR_GL_FRAMEBUFFER, fFBO)); |
60 SK_GL(*this, GenRenderbuffers(1, &fColorBufferID)); | 58 SK_GL(*this, GenRenderbuffers(1, &fColorBufferID)); |
61 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID)); | 59 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fColorBufferID)); |
62 if (kES_GrGLBinding == bindingInUse) { | 60 if (kGLES_GrGLStandard == this->gl()->fStandard) { |
63 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, | 61 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, |
64 GR_GL_RGBA8, | 62 GR_GL_RGBA8, |
65 width, height)); | 63 width, height)); |
66 } else { | 64 } else { |
67 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, | 65 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, |
68 GR_GL_RGBA, | 66 GR_GL_RGBA, |
69 width, height)); | 67 width, height)); |
70 } | 68 } |
71 SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 69 SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
72 GR_GL_COLOR_ATTACHMENT0, | 70 GR_GL_COLOR_ATTACHMENT0, |
73 GR_GL_RENDERBUFFER, | 71 GR_GL_RENDERBUFFER, |
74 fColorBufferID)); | 72 fColorBufferID)); |
75 SK_GL(*this, GenRenderbuffers(1, &fDepthStencilBufferID)); | 73 SK_GL(*this, GenRenderbuffers(1, &fDepthStencilBufferID)); |
76 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fDepthStencilBufferID)
); | 74 SK_GL(*this, BindRenderbuffer(GR_GL_RENDERBUFFER, fDepthStencilBufferID)
); |
77 | 75 |
78 // Some drivers that support packed depth stencil will only succeed | 76 // Some drivers that support packed depth stencil will only succeed |
79 // in binding a packed format an FBO. However, we can't rely on packed | 77 // in binding a packed format an FBO. However, we can't rely on packed |
80 // depth stencil being available. | 78 // depth stencil being available. |
81 bool supportsPackedDepthStencil; | 79 bool supportsPackedDepthStencil; |
82 if (kES_GrGLBinding == bindingInUse) { | 80 if (kGLES_GrGLStandard == this->gl()->fStandard) { |
83 supportsPackedDepthStencil = version >= GR_GL_VER(3,0) || | 81 supportsPackedDepthStencil = version >= GR_GL_VER(3,0) || |
84 this->hasExtension("GL_OES_packed_depth
_stencil"); | 82 this->hasExtension("GL_OES_packed_depth
_stencil"); |
85 } else { | 83 } else { |
86 supportsPackedDepthStencil = version >= GR_GL_VER(3,0) || | 84 supportsPackedDepthStencil = version >= GR_GL_VER(3,0) || |
87 this->hasExtension("GL_EXT_packed_depth
_stencil") || | 85 this->hasExtension("GL_EXT_packed_depth
_stencil") || |
88 this->hasExtension("GL_ARB_framebuffer_
object"); | 86 this->hasExtension("GL_ARB_framebuffer_
object"); |
89 } | 87 } |
90 | 88 |
91 if (supportsPackedDepthStencil) { | 89 if (supportsPackedDepthStencil) { |
92 // ES2 requires sized internal formats for RenderbufferStorage | 90 // ES2 requires sized internal formats for RenderbufferStorage |
93 // On Desktop we let the driver decide. | 91 // On Desktop we let the driver decide. |
94 GrGLenum format = kES_GrGLBinding == bindingInUse ? | 92 GrGLenum format = kGLES_GrGLStandard == this->gl()->fStandard ? |
95 GR_GL_DEPTH24_STENCIL8 : | 93 GR_GL_DEPTH24_STENCIL8 : |
96 GR_GL_DEPTH_STENCIL; | 94 GR_GL_DEPTH_STENCIL; |
97 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, | 95 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, |
98 format, | 96 format, |
99 width, height)); | 97 width, height)); |
100 SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 98 SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
101 GR_GL_DEPTH_ATTACHMENT, | 99 GR_GL_DEPTH_ATTACHMENT, |
102 GR_GL_RENDERBUFFER, | 100 GR_GL_RENDERBUFFER, |
103 fDepthStencilBufferID)); | 101 fDepthStencilBufferID)); |
104 } else { | 102 } else { |
105 GrGLenum format = kES_GrGLBinding == bindingInUse ? | 103 GrGLenum format = kGLES_GrGLStandard == this->gl()->fStandard ? GR_G
L_STENCIL_INDEX8 : |
106 GR_GL_STENCIL_INDEX8 : | 104 GR_GL_
STENCIL_INDEX; |
107 GR_GL_STENCIL_INDEX; | |
108 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, | 105 SK_GL(*this, RenderbufferStorage(GR_GL_RENDERBUFFER, |
109 format, | 106 format, |
110 width, height)); | 107 width, height)); |
111 } | 108 } |
112 SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, | 109 SK_GL(*this, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
113 GR_GL_STENCIL_ATTACHMENT, | 110 GR_GL_STENCIL_ATTACHMENT, |
114 GR_GL_RENDERBUFFER, | 111 GR_GL_RENDERBUFFER, |
115 fDepthStencilBufferID)); | 112 fDepthStencilBufferID)); |
116 SK_GL(*this, Viewport(0, 0, width, height)); | 113 SK_GL(*this, Viewport(0, 0, width, height)); |
117 SK_GL(*this, ClearStencil(0)); | 114 SK_GL(*this, ClearStencil(0)); |
(...skipping 11 matching lines...) Expand all Loading... |
129 fGL->unref(); | 126 fGL->unref(); |
130 fGL = NULL; | 127 fGL = NULL; |
131 this->destroyGLContext(); | 128 this->destroyGLContext(); |
132 return false; | 129 return false; |
133 } else { | 130 } else { |
134 return true; | 131 return true; |
135 } | 132 } |
136 } | 133 } |
137 return false; | 134 return false; |
138 } | 135 } |
OLD | NEW |