OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 21 matching lines...) Expand all Loading... |
32 namespace WebCore { | 32 namespace WebCore { |
33 | 33 |
34 PassRefPtr<WebGLTexture> WebGLTexture::create(WebGLRenderingContext* ctx) | 34 PassRefPtr<WebGLTexture> WebGLTexture::create(WebGLRenderingContext* ctx) |
35 { | 35 { |
36 return adoptRef(new WebGLTexture(ctx)); | 36 return adoptRef(new WebGLTexture(ctx)); |
37 } | 37 } |
38 | 38 |
39 WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx) | 39 WebGLTexture::WebGLTexture(WebGLRenderingContext* ctx) |
40 : WebGLSharedObject(ctx) | 40 : WebGLSharedObject(ctx) |
41 , m_target(0) | 41 , m_target(0) |
42 , m_minFilter(GraphicsContext3D::NEAREST_MIPMAP_LINEAR) | 42 , m_minFilter(GL_NEAREST_MIPMAP_LINEAR) |
43 , m_magFilter(GraphicsContext3D::LINEAR) | 43 , m_magFilter(GL_LINEAR) |
44 , m_wrapS(GraphicsContext3D::REPEAT) | 44 , m_wrapS(GL_REPEAT) |
45 , m_wrapT(GraphicsContext3D::REPEAT) | 45 , m_wrapT(GL_REPEAT) |
46 , m_isNPOT(false) | 46 , m_isNPOT(false) |
47 , m_isCubeComplete(false) | 47 , m_isCubeComplete(false) |
48 , m_isComplete(false) | 48 , m_isComplete(false) |
49 , m_needToUseBlackTexture(false) | 49 , m_needToUseBlackTexture(false) |
50 , m_isFloatType(false) | 50 , m_isFloatType(false) |
51 , m_isHalfFloatType(false) | 51 , m_isHalfFloatType(false) |
52 { | 52 { |
53 ScriptWrappable::init(this); | 53 ScriptWrappable::init(this); |
54 setObject(ctx->graphicsContext3D()->createTexture()); | 54 setObject(ctx->graphicsContext3D()->createTexture()); |
55 } | 55 } |
56 | 56 |
57 WebGLTexture::~WebGLTexture() | 57 WebGLTexture::~WebGLTexture() |
58 { | 58 { |
59 deleteObject(0); | 59 deleteObject(0); |
60 } | 60 } |
61 | 61 |
62 void WebGLTexture::setTarget(GC3Denum target, GC3Dint maxLevel) | 62 void WebGLTexture::setTarget(GC3Denum target, GC3Dint maxLevel) |
63 { | 63 { |
64 if (!object()) | 64 if (!object()) |
65 return; | 65 return; |
66 // Target is finalized the first time bindTexture() is called. | 66 // Target is finalized the first time bindTexture() is called. |
67 if (m_target) | 67 if (m_target) |
68 return; | 68 return; |
69 switch (target) { | 69 switch (target) { |
70 case GraphicsContext3D::TEXTURE_2D: | 70 case GL_TEXTURE_2D: |
71 m_target = target; | 71 m_target = target; |
72 m_info.resize(1); | 72 m_info.resize(1); |
73 m_info[0].resize(maxLevel); | 73 m_info[0].resize(maxLevel); |
74 break; | 74 break; |
75 case GraphicsContext3D::TEXTURE_CUBE_MAP: | 75 case GL_TEXTURE_CUBE_MAP: |
76 m_target = target; | 76 m_target = target; |
77 m_info.resize(6); | 77 m_info.resize(6); |
78 for (int ii = 0; ii < 6; ++ii) | 78 for (int ii = 0; ii < 6; ++ii) |
79 m_info[ii].resize(maxLevel); | 79 m_info[ii].resize(maxLevel); |
80 break; | 80 break; |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void WebGLTexture::setParameteri(GC3Denum pname, GC3Dint param) | 84 void WebGLTexture::setParameteri(GC3Denum pname, GC3Dint param) |
85 { | 85 { |
86 if (!object() || !m_target) | 86 if (!object() || !m_target) |
87 return; | 87 return; |
88 switch (pname) { | 88 switch (pname) { |
89 case GraphicsContext3D::TEXTURE_MIN_FILTER: | 89 case GL_TEXTURE_MIN_FILTER: |
90 switch (param) { | 90 switch (param) { |
91 case GraphicsContext3D::NEAREST: | 91 case GL_NEAREST: |
92 case GraphicsContext3D::LINEAR: | 92 case GL_LINEAR: |
93 case GraphicsContext3D::NEAREST_MIPMAP_NEAREST: | 93 case GL_NEAREST_MIPMAP_NEAREST: |
94 case GraphicsContext3D::LINEAR_MIPMAP_NEAREST: | 94 case GL_LINEAR_MIPMAP_NEAREST: |
95 case GraphicsContext3D::NEAREST_MIPMAP_LINEAR: | 95 case GL_NEAREST_MIPMAP_LINEAR: |
96 case GraphicsContext3D::LINEAR_MIPMAP_LINEAR: | 96 case GL_LINEAR_MIPMAP_LINEAR: |
97 m_minFilter = param; | 97 m_minFilter = param; |
98 break; | 98 break; |
99 } | 99 } |
100 break; | 100 break; |
101 case GraphicsContext3D::TEXTURE_MAG_FILTER: | 101 case GL_TEXTURE_MAG_FILTER: |
102 switch (param) { | 102 switch (param) { |
103 case GraphicsContext3D::NEAREST: | 103 case GL_NEAREST: |
104 case GraphicsContext3D::LINEAR: | 104 case GL_LINEAR: |
105 m_magFilter = param; | 105 m_magFilter = param; |
106 break; | 106 break; |
107 } | 107 } |
108 break; | 108 break; |
109 case GraphicsContext3D::TEXTURE_WRAP_S: | 109 case GL_TEXTURE_WRAP_S: |
110 switch (param) { | 110 switch (param) { |
111 case GraphicsContext3D::CLAMP_TO_EDGE: | 111 case GL_CLAMP_TO_EDGE: |
112 case GraphicsContext3D::MIRRORED_REPEAT: | 112 case GL_MIRRORED_REPEAT: |
113 case GraphicsContext3D::REPEAT: | 113 case GL_REPEAT: |
114 m_wrapS = param; | 114 m_wrapS = param; |
115 break; | 115 break; |
116 } | 116 } |
117 break; | 117 break; |
118 case GraphicsContext3D::TEXTURE_WRAP_T: | 118 case GL_TEXTURE_WRAP_T: |
119 switch (param) { | 119 switch (param) { |
120 case GraphicsContext3D::CLAMP_TO_EDGE: | 120 case GL_CLAMP_TO_EDGE: |
121 case GraphicsContext3D::MIRRORED_REPEAT: | 121 case GL_MIRRORED_REPEAT: |
122 case GraphicsContext3D::REPEAT: | 122 case GL_REPEAT: |
123 m_wrapT = param; | 123 m_wrapT = param; |
124 break; | 124 break; |
125 } | 125 } |
126 break; | 126 break; |
127 default: | 127 default: |
128 return; | 128 return; |
129 } | 129 } |
130 update(); | 130 update(); |
131 } | 131 } |
132 | 132 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 return m_isNPOT; | 232 return m_isNPOT; |
233 } | 233 } |
234 | 234 |
235 bool WebGLTexture::needToUseBlackTexture(TextureExtensionFlag flag) const | 235 bool WebGLTexture::needToUseBlackTexture(TextureExtensionFlag flag) const |
236 { | 236 { |
237 if (!object()) | 237 if (!object()) |
238 return false; | 238 return false; |
239 if (m_needToUseBlackTexture) | 239 if (m_needToUseBlackTexture) |
240 return true; | 240 return true; |
241 if ((m_isFloatType && !(flag & TextureFloatLinearExtensionEnabled)) || (m_is
HalfFloatType && !(flag && TextureHalfFloatLinearExtensionEnabled))) { | 241 if ((m_isFloatType && !(flag & TextureFloatLinearExtensionEnabled)) || (m_is
HalfFloatType && !(flag && TextureHalfFloatLinearExtensionEnabled))) { |
242 if (m_magFilter != GraphicsContext3D::NEAREST || (m_minFilter != Graphic
sContext3D::NEAREST && m_minFilter != GraphicsContext3D::NEAREST_MIPMAP_NEAREST)
) | 242 if (m_magFilter != GL_NEAREST || (m_minFilter != GL_NEAREST && m_minFilt
er != GL_NEAREST_MIPMAP_NEAREST)) |
243 return true; | 243 return true; |
244 } | 244 } |
245 return false; | 245 return false; |
246 } | 246 } |
247 | 247 |
248 void WebGLTexture::deleteObjectImpl(GraphicsContext3D* context3d, Platform3DObje
ct object) | 248 void WebGLTexture::deleteObjectImpl(GraphicsContext3D* context3d, Platform3DObje
ct object) |
249 { | 249 { |
250 context3d->deleteTexture(object); | 250 context3d->deleteTexture(object); |
251 } | 251 } |
252 | 252 |
253 int WebGLTexture::mapTargetToIndex(GC3Denum target) const | 253 int WebGLTexture::mapTargetToIndex(GC3Denum target) const |
254 { | 254 { |
255 if (m_target == GraphicsContext3D::TEXTURE_2D) { | 255 if (m_target == GL_TEXTURE_2D) { |
256 if (target == GraphicsContext3D::TEXTURE_2D) | 256 if (target == GL_TEXTURE_2D) |
257 return 0; | 257 return 0; |
258 } else if (m_target == GraphicsContext3D::TEXTURE_CUBE_MAP) { | 258 } else if (m_target == GL_TEXTURE_CUBE_MAP) { |
259 switch (target) { | 259 switch (target) { |
260 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: | 260 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
261 return 0; | 261 return 0; |
262 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: | 262 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
263 return 1; | 263 return 1; |
264 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: | 264 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
265 return 2; | 265 return 2; |
266 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: | 266 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
267 return 3; | 267 return 3; |
268 case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: | 268 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
269 return 4; | 269 return 4; |
270 case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: | 270 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
271 return 5; | 271 return 5; |
272 } | 272 } |
273 } | 273 } |
274 return -1; | 274 return -1; |
275 } | 275 } |
276 | 276 |
277 bool WebGLTexture::canGenerateMipmaps() | 277 bool WebGLTexture::canGenerateMipmaps() |
278 { | 278 { |
279 if (isNPOT()) | 279 if (isNPOT()) |
280 return false; | 280 return false; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 if (!info.valid | 346 if (!info.valid |
347 || info.width != width || info.height != height | 347 || info.width != width || info.height != height |
348 || info.internalFormat != info0.internalFormat || info.type
!= info0.type) { | 348 || info.internalFormat != info0.internalFormat || info.type
!= info0.type) { |
349 m_isComplete = false; | 349 m_isComplete = false; |
350 break; | 350 break; |
351 } | 351 } |
352 | 352 |
353 } | 353 } |
354 } | 354 } |
355 } | 355 } |
356 m_isFloatType = m_info[0][0].type == GraphicsContext3D::FLOAT; | 356 m_isFloatType = m_info[0][0].type == GL_FLOAT; |
357 m_isHalfFloatType = m_info[0][0].type == GraphicsContext3D::HALF_FLOAT_OES; | 357 m_isHalfFloatType = m_info[0][0].type == GL_HALF_FLOAT_OES; |
358 | 358 |
359 m_needToUseBlackTexture = false; | 359 m_needToUseBlackTexture = false; |
360 // NPOT | 360 // NPOT |
361 if (m_isNPOT && ((m_minFilter != GraphicsContext3D::NEAREST && m_minFilter !
= GraphicsContext3D::LINEAR) | 361 if (m_isNPOT && ((m_minFilter != GL_NEAREST && m_minFilter != GL_LINEAR) |
362 || m_wrapS != GraphicsContext3D::CLAMP_TO_EDGE || m_wrapT !
= GraphicsContext3D::CLAMP_TO_EDGE)) | 362 || m_wrapS != GL_CLAMP_TO_EDGE || m_wrapT != GL_CLAMP_TO_EDGE)) |
363 m_needToUseBlackTexture = true; | 363 m_needToUseBlackTexture = true; |
364 // If it is a Cube texture, check Cube Completeness first | 364 // If it is a Cube texture, check Cube Completeness first |
365 if (m_info.size() > 1 && !m_isCubeComplete) | 365 if (m_info.size() > 1 && !m_isCubeComplete) |
366 m_needToUseBlackTexture = true; | 366 m_needToUseBlackTexture = true; |
367 // Completeness | 367 // Completeness |
368 if (!m_isComplete && m_minFilter != GraphicsContext3D::NEAREST && m_minFilte
r != GraphicsContext3D::LINEAR) | 368 if (!m_isComplete && m_minFilter != GL_NEAREST && m_minFilter != GL_LINEAR) |
369 m_needToUseBlackTexture = true; | 369 m_needToUseBlackTexture = true; |
370 } | 370 } |
371 | 371 |
372 const WebGLTexture::LevelInfo* WebGLTexture::getLevelInfo(GC3Denum target, GC3Di
nt level) const | 372 const WebGLTexture::LevelInfo* WebGLTexture::getLevelInfo(GC3Denum target, GC3Di
nt level) const |
373 { | 373 { |
374 if (!object() || !m_target) | 374 if (!object() || !m_target) |
375 return 0; | 375 return 0; |
376 int targetIndex = mapTargetToIndex(target); | 376 int targetIndex = mapTargetToIndex(target); |
377 if (targetIndex < 0 || targetIndex >= static_cast<int>(m_info.size())) | 377 if (targetIndex < 0 || targetIndex >= static_cast<int>(m_info.size())) |
378 return 0; | 378 return 0; |
379 if (level < 0 || level >= static_cast<GC3Dint>(m_info[targetIndex].size())) | 379 if (level < 0 || level >= static_cast<GC3Dint>(m_info[targetIndex].size())) |
380 return 0; | 380 return 0; |
381 return &(m_info[targetIndex][level]); | 381 return &(m_info[targetIndex][level]); |
382 } | 382 } |
383 | 383 |
384 } | 384 } |
OLD | NEW |