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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "core/loader/FrameLoader.h" | 46 #include "core/loader/FrameLoader.h" |
47 #include "core/loader/FrameLoaderClient.h" | 47 #include "core/loader/FrameLoaderClient.h" |
48 #include "gpu/command_buffer/client/gles2_interface.h" | 48 #include "gpu/command_buffer/client/gles2_interface.h" |
49 #include "modules/webgl/ANGLEInstancedArrays.h" | 49 #include "modules/webgl/ANGLEInstancedArrays.h" |
50 #include "modules/webgl/CHROMIUMSubscribeUniform.h" | 50 #include "modules/webgl/CHROMIUMSubscribeUniform.h" |
51 #include "modules/webgl/CHROMIUMValuebuffer.h" | 51 #include "modules/webgl/CHROMIUMValuebuffer.h" |
52 #include "modules/webgl/EXTBlendMinMax.h" | 52 #include "modules/webgl/EXTBlendMinMax.h" |
53 #include "modules/webgl/EXTFragDepth.h" | 53 #include "modules/webgl/EXTFragDepth.h" |
54 #include "modules/webgl/EXTShaderTextureLOD.h" | 54 #include "modules/webgl/EXTShaderTextureLOD.h" |
55 #include "modules/webgl/EXTTextureFilterAnisotropic.h" | 55 #include "modules/webgl/EXTTextureFilterAnisotropic.h" |
| 56 #include "modules/webgl/GLStringQuery.h" |
56 #include "modules/webgl/OESElementIndexUint.h" | 57 #include "modules/webgl/OESElementIndexUint.h" |
57 #include "modules/webgl/OESStandardDerivatives.h" | 58 #include "modules/webgl/OESStandardDerivatives.h" |
58 #include "modules/webgl/OESTextureFloat.h" | 59 #include "modules/webgl/OESTextureFloat.h" |
59 #include "modules/webgl/OESTextureFloatLinear.h" | 60 #include "modules/webgl/OESTextureFloatLinear.h" |
60 #include "modules/webgl/OESTextureHalfFloat.h" | 61 #include "modules/webgl/OESTextureHalfFloat.h" |
61 #include "modules/webgl/OESTextureHalfFloatLinear.h" | 62 #include "modules/webgl/OESTextureHalfFloatLinear.h" |
62 #include "modules/webgl/OESVertexArrayObject.h" | 63 #include "modules/webgl/OESVertexArrayObject.h" |
63 #include "modules/webgl/WebGLActiveInfo.h" | 64 #include "modules/webgl/WebGLActiveInfo.h" |
64 #include "modules/webgl/WebGLBuffer.h" | 65 #include "modules/webgl/WebGLBuffer.h" |
65 #include "modules/webgl/WebGLCompressedTextureASTC.h" | 66 #include "modules/webgl/WebGLCompressedTextureASTC.h" |
(...skipping 2203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2269 return; | 2270 return; |
2270 if (!validateTextureBinding("generateMipmap", target)) | 2271 if (!validateTextureBinding("generateMipmap", target)) |
2271 return; | 2272 return; |
2272 contextGL()->GenerateMipmap(target); | 2273 contextGL()->GenerateMipmap(target); |
2273 } | 2274 } |
2274 | 2275 |
2275 WebGLActiveInfo* WebGLRenderingContextBase::getActiveAttrib(WebGLProgram* progra
m, GLuint index) | 2276 WebGLActiveInfo* WebGLRenderingContextBase::getActiveAttrib(WebGLProgram* progra
m, GLuint index) |
2276 { | 2277 { |
2277 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program)) | 2278 if (isContextLost() || !validateWebGLObject("getActiveAttrib", program)) |
2278 return nullptr; | 2279 return nullptr; |
2279 WebGraphicsContext3D::ActiveInfo info; | |
2280 GLuint programId = objectNonZero(program); | 2280 GLuint programId = objectNonZero(program); |
2281 GLint maxNameLength = -1; | 2281 GLint maxNameLength = -1; |
2282 contextGL()->GetProgramiv(programId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNam
eLength); | 2282 contextGL()->GetProgramiv(programId, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNam
eLength); |
2283 if (maxNameLength < 0) | 2283 if (maxNameLength < 0) |
2284 return nullptr; | 2284 return nullptr; |
2285 if (maxNameLength == 0) { | 2285 if (maxNameLength == 0) { |
2286 synthesizeGLError(GL_INVALID_VALUE, "getActiveAttrib", "no active attrib
utes exist"); | 2286 synthesizeGLError(GL_INVALID_VALUE, "getActiveAttrib", "no active attrib
utes exist"); |
2287 return nullptr; | 2287 return nullptr; |
2288 } | 2288 } |
2289 if (!webContext()->getActiveAttrib(objectOrZero(program), index, info)) | 2289 LChar* namePtr; |
| 2290 RefPtr<StringImpl> nameImpl = StringImpl::createUninitialized(maxNameLength,
namePtr); |
| 2291 GLsizei length = 0; |
| 2292 GLint size = -1; |
| 2293 GLenum type = 0; |
| 2294 contextGL()->GetActiveAttrib(programId, index, maxNameLength, &length, &size
, &type, reinterpret_cast<GLchar*>(namePtr)); |
| 2295 if (size < 0) |
2290 return nullptr; | 2296 return nullptr; |
2291 return WebGLActiveInfo::create(info.name, info.type, info.size); | 2297 return WebGLActiveInfo::create(nameImpl->substring(0, length), type, size); |
2292 } | 2298 } |
2293 | 2299 |
2294 WebGLActiveInfo* WebGLRenderingContextBase::getActiveUniform(WebGLProgram* progr
am, GLuint index) | 2300 WebGLActiveInfo* WebGLRenderingContextBase::getActiveUniform(WebGLProgram* progr
am, GLuint index) |
2295 { | 2301 { |
2296 if (isContextLost() || !validateWebGLObject("getActiveUniform", program)) | 2302 if (isContextLost() || !validateWebGLObject("getActiveUniform", program)) |
2297 return nullptr; | 2303 return nullptr; |
2298 GLuint programId = objectNonZero(program); | 2304 GLuint programId = objectNonZero(program); |
2299 GLint maxNameLength = -1; | 2305 GLint maxNameLength = -1; |
2300 contextGL()->GetProgramiv(programId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameL
ength); | 2306 contextGL()->GetProgramiv(programId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameL
ength); |
2301 if (maxNameLength < 0) | 2307 if (maxNameLength < 0) |
2302 return nullptr; | 2308 return nullptr; |
2303 if (maxNameLength == 0) { | 2309 if (maxNameLength == 0) { |
2304 synthesizeGLError(GL_INVALID_VALUE, "getActiveUniform", "no active unifo
rms exist"); | 2310 synthesizeGLError(GL_INVALID_VALUE, "getActiveUniform", "no active unifo
rms exist"); |
2305 return nullptr; | 2311 return nullptr; |
2306 } | 2312 } |
2307 WebGraphicsContext3D::ActiveInfo info; | 2313 LChar* namePtr; |
2308 if (!webContext()->getActiveUniform(programId, index, info)) | 2314 RefPtr<StringImpl> nameImpl = StringImpl::createUninitialized(maxNameLength,
namePtr); |
| 2315 GLsizei length = 0; |
| 2316 GLint size = -1; |
| 2317 GLenum type = 0; |
| 2318 contextGL()->GetActiveUniform(programId, index, maxNameLength, &length, &siz
e, &type, reinterpret_cast<GLchar*>(namePtr)); |
| 2319 if (size < 0) |
2309 return nullptr; | 2320 return nullptr; |
2310 return WebGLActiveInfo::create(info.name, info.type, info.size); | 2321 return WebGLActiveInfo::create(nameImpl->substring(0, length), type, size); |
2311 } | 2322 } |
2312 | 2323 |
2313 Nullable<HeapVector<Member<WebGLShader>>> WebGLRenderingContextBase::getAttached
Shaders(WebGLProgram* program) | 2324 Nullable<HeapVector<Member<WebGLShader>>> WebGLRenderingContextBase::getAttached
Shaders(WebGLProgram* program) |
2314 { | 2325 { |
2315 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program)) | 2326 if (isContextLost() || !validateWebGLObject("getAttachedShaders", program)) |
2316 return nullptr; | 2327 return nullptr; |
2317 | 2328 |
2318 HeapVector<Member<WebGLShader>> shaderObjects; | 2329 HeapVector<Member<WebGLShader>> shaderObjects; |
2319 const GLenum shaderType[] = { | 2330 const GLenum shaderType[] = { |
2320 GL_VERTEX_SHADER, | 2331 GL_VERTEX_SHADER, |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2831 default: | 2842 default: |
2832 synthesizeGLError(GL_INVALID_ENUM, "getProgramParameter", "invalid param
eter name"); | 2843 synthesizeGLError(GL_INVALID_ENUM, "getProgramParameter", "invalid param
eter name"); |
2833 return ScriptValue::createNull(scriptState); | 2844 return ScriptValue::createNull(scriptState); |
2834 } | 2845 } |
2835 } | 2846 } |
2836 | 2847 |
2837 String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program) | 2848 String WebGLRenderingContextBase::getProgramInfoLog(WebGLProgram* program) |
2838 { | 2849 { |
2839 if (isContextLost() || !validateWebGLObject("getProgramInfoLog", program)) | 2850 if (isContextLost() || !validateWebGLObject("getProgramInfoLog", program)) |
2840 return String(); | 2851 return String(); |
2841 return ensureNotNull(webContext()->getProgramInfoLog(objectOrZero(program)))
; | 2852 GLStringQuery query(contextGL()); |
| 2853 return query.Run<GLStringQuery::ProgramInfoLog>(objectNonZero(program)); |
2842 } | 2854 } |
2843 | 2855 |
2844 ScriptValue WebGLRenderingContextBase::getRenderbufferParameter(ScriptState* scr
iptState, GLenum target, GLenum pname) | 2856 ScriptValue WebGLRenderingContextBase::getRenderbufferParameter(ScriptState* scr
iptState, GLenum target, GLenum pname) |
2845 { | 2857 { |
2846 if (isContextLost()) | 2858 if (isContextLost()) |
2847 return ScriptValue::createNull(scriptState); | 2859 return ScriptValue::createNull(scriptState); |
2848 if (target != GL_RENDERBUFFER) { | 2860 if (target != GL_RENDERBUFFER) { |
2849 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid
target"); | 2861 synthesizeGLError(GL_INVALID_ENUM, "getRenderbufferParameter", "invalid
target"); |
2850 return ScriptValue::createNull(scriptState); | 2862 return ScriptValue::createNull(scriptState); |
2851 } | 2863 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2898 default: | 2910 default: |
2899 synthesizeGLError(GL_INVALID_ENUM, "getShaderParameter", "invalid parame
ter name"); | 2911 synthesizeGLError(GL_INVALID_ENUM, "getShaderParameter", "invalid parame
ter name"); |
2900 return ScriptValue::createNull(scriptState); | 2912 return ScriptValue::createNull(scriptState); |
2901 } | 2913 } |
2902 } | 2914 } |
2903 | 2915 |
2904 String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader) | 2916 String WebGLRenderingContextBase::getShaderInfoLog(WebGLShader* shader) |
2905 { | 2917 { |
2906 if (isContextLost() || !validateWebGLObject("getShaderInfoLog", shader)) | 2918 if (isContextLost() || !validateWebGLObject("getShaderInfoLog", shader)) |
2907 return String(); | 2919 return String(); |
2908 return ensureNotNull(webContext()->getShaderInfoLog(objectOrZero(shader))); | 2920 GLStringQuery query(contextGL()); |
| 2921 return query.Run<GLStringQuery::ShaderInfoLog>(objectNonZero(shader)); |
2909 } | 2922 } |
2910 | 2923 |
2911 WebGLShaderPrecisionFormat* WebGLRenderingContextBase::getShaderPrecisionFormat(
GLenum shaderType, GLenum precisionType) | 2924 WebGLShaderPrecisionFormat* WebGLRenderingContextBase::getShaderPrecisionFormat(
GLenum shaderType, GLenum precisionType) |
2912 { | 2925 { |
2913 if (isContextLost()) | 2926 if (isContextLost()) |
2914 return nullptr; | 2927 return nullptr; |
2915 switch (shaderType) { | 2928 switch (shaderType) { |
2916 case GL_VERTEX_SHADER: | 2929 case GL_VERTEX_SHADER: |
2917 case GL_FRAGMENT_SHADER: | 2930 case GL_FRAGMENT_SHADER: |
2918 break; | 2931 break; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3000 ScriptValue WebGLRenderingContextBase::getUniform(ScriptState* scriptState, WebG
LProgram* program, const WebGLUniformLocation* uniformLocation) | 3013 ScriptValue WebGLRenderingContextBase::getUniform(ScriptState* scriptState, WebG
LProgram* program, const WebGLUniformLocation* uniformLocation) |
3001 { | 3014 { |
3002 if (isContextLost() || !validateWebGLObject("getUniform", program)) | 3015 if (isContextLost() || !validateWebGLObject("getUniform", program)) |
3003 return ScriptValue::createNull(scriptState); | 3016 return ScriptValue::createNull(scriptState); |
3004 if (!uniformLocation || uniformLocation->program() != program) { | 3017 if (!uniformLocation || uniformLocation->program() != program) { |
3005 synthesizeGLError(GL_INVALID_OPERATION, "getUniform", "no uniformlocatio
n or not valid for this program"); | 3018 synthesizeGLError(GL_INVALID_OPERATION, "getUniform", "no uniformlocatio
n or not valid for this program"); |
3006 return ScriptValue::createNull(scriptState); | 3019 return ScriptValue::createNull(scriptState); |
3007 } | 3020 } |
3008 GLint location = uniformLocation->location(); | 3021 GLint location = uniformLocation->location(); |
3009 | 3022 |
| 3023 GLuint programId = objectNonZero(program); |
| 3024 GLint maxNameLength = -1; |
| 3025 contextGL()->GetProgramiv(programId, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameL
ength); |
| 3026 if (maxNameLength < 0) |
| 3027 return ScriptValue::createNull(scriptState); |
| 3028 if (maxNameLength == 0) { |
| 3029 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "no active uniforms ex
ist"); |
| 3030 return ScriptValue::createNull(scriptState); |
| 3031 } |
| 3032 |
3010 // FIXME: make this more efficient using WebGLUniformLocation and caching ty
pes in it | 3033 // FIXME: make this more efficient using WebGLUniformLocation and caching ty
pes in it |
3011 GLint activeUniforms = 0; | 3034 GLint activeUniforms = 0; |
3012 contextGL()->GetProgramiv(objectOrZero(program), GL_ACTIVE_UNIFORMS, &active
Uniforms); | 3035 contextGL()->GetProgramiv(programId, GL_ACTIVE_UNIFORMS, &activeUniforms); |
3013 for (GLint i = 0; i < activeUniforms; i++) { | 3036 for (GLint i = 0; i < activeUniforms; i++) { |
3014 WebGraphicsContext3D::ActiveInfo info; | 3037 LChar* namePtr; |
3015 if (!webContext()->getActiveUniform(objectOrZero(program), i, info)) | 3038 RefPtr<StringImpl> nameImpl = StringImpl::createUninitialized(maxNameLen
gth, namePtr); |
| 3039 GLsizei length = 0; |
| 3040 GLint size = -1; |
| 3041 GLenum type = 0; |
| 3042 contextGL()->GetActiveUniform(programId, i, maxNameLength, &length, &siz
e, &type, reinterpret_cast<GLchar*>(namePtr)); |
| 3043 if (size < 0) |
3016 return ScriptValue::createNull(scriptState); | 3044 return ScriptValue::createNull(scriptState); |
3017 String name = info.name; | 3045 String name(nameImpl->substring(0, length)); |
3018 StringBuilder nameBuilder; | 3046 StringBuilder nameBuilder; |
3019 // Strip "[0]" from the name if it's an array. | 3047 // Strip "[0]" from the name if it's an array. |
3020 if (info.size > 1 && name.endsWith("[0]")) | 3048 if (size > 1 && name.endsWith("[0]")) |
3021 info.name = name.left(name.length() - 3); | 3049 name = name.left(name.length() - 3); |
3022 // If it's an array, we need to iterate through each element, appending
"[index]" to the name. | 3050 // If it's an array, we need to iterate through each element, appending
"[index]" to the name. |
3023 for (GLint index = 0; index < info.size; ++index) { | 3051 for (GLint index = 0; index < size; ++index) { |
3024 nameBuilder.clear(); | 3052 nameBuilder.clear(); |
3025 nameBuilder.append(info.name); | 3053 nameBuilder.append(name); |
3026 if (info.size > 1 && index >= 1) { | 3054 if (size > 1 && index >= 1) { |
3027 nameBuilder.append('['); | 3055 nameBuilder.append('['); |
3028 nameBuilder.appendNumber(index); | 3056 nameBuilder.appendNumber(index); |
3029 nameBuilder.append(']'); | 3057 nameBuilder.append(']'); |
3030 } | 3058 } |
3031 // Now need to look this up by name again to find its location | 3059 // Now need to look this up by name again to find its location |
3032 GLint loc = contextGL()->GetUniformLocation(objectOrZero(program), n
ameBuilder.toString().utf8().data()); | 3060 GLint loc = contextGL()->GetUniformLocation(objectOrZero(program), n
ameBuilder.toString().utf8().data()); |
3033 if (loc == location) { | 3061 if (loc == location) { |
3034 // Found it. Use the type in the ActiveInfo to determine the ret
urn type. | 3062 // Found it. Use the type in the ActiveInfo to determine the ret
urn type. |
3035 GLenum baseType; | 3063 GLenum baseType; |
3036 unsigned length; | 3064 unsigned length; |
3037 switch (info.type) { | 3065 switch (type) { |
3038 case GL_BOOL: | 3066 case GL_BOOL: |
3039 baseType = GL_BOOL; | 3067 baseType = GL_BOOL; |
3040 length = 1; | 3068 length = 1; |
3041 break; | 3069 break; |
3042 case GL_BOOL_VEC2: | 3070 case GL_BOOL_VEC2: |
3043 baseType = GL_BOOL; | 3071 baseType = GL_BOOL; |
3044 length = 2; | 3072 length = 2; |
3045 break; | 3073 break; |
3046 case GL_BOOL_VEC3: | 3074 case GL_BOOL_VEC3: |
3047 baseType = GL_BOOL; | 3075 baseType = GL_BOOL; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3100 baseType = GL_INT; | 3128 baseType = GL_INT; |
3101 length = 1; | 3129 length = 1; |
3102 break; | 3130 break; |
3103 default: | 3131 default: |
3104 if (!isWebGL2OrHigher()) { | 3132 if (!isWebGL2OrHigher()) { |
3105 // Can't handle this type | 3133 // Can't handle this type |
3106 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "unhan
dled type"); | 3134 synthesizeGLError(GL_INVALID_VALUE, "getUniform", "unhan
dled type"); |
3107 return ScriptValue::createNull(scriptState); | 3135 return ScriptValue::createNull(scriptState); |
3108 } | 3136 } |
3109 // handle GLenums for WebGL 2.0 or higher | 3137 // handle GLenums for WebGL 2.0 or higher |
3110 switch (info.type) { | 3138 switch (type) { |
3111 case GL_UNSIGNED_INT: | 3139 case GL_UNSIGNED_INT: |
3112 baseType = GL_UNSIGNED_INT; | 3140 baseType = GL_UNSIGNED_INT; |
3113 length = 1; | 3141 length = 1; |
3114 break; | 3142 break; |
3115 case GL_UNSIGNED_INT_VEC2: | 3143 case GL_UNSIGNED_INT_VEC2: |
3116 baseType = GL_UNSIGNED_INT; | 3144 baseType = GL_UNSIGNED_INT; |
3117 length = 2; | 3145 length = 2; |
3118 break; | 3146 break; |
3119 case GL_UNSIGNED_INT_VEC3: | 3147 case GL_UNSIGNED_INT_VEC3: |
3120 baseType = GL_UNSIGNED_INT; | 3148 baseType = GL_UNSIGNED_INT; |
(...skipping 3190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6311 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); | 6339 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, 1); |
6312 } | 6340 } |
6313 | 6341 |
6314 void WebGLRenderingContextBase::restoreUnpackParameters() | 6342 void WebGLRenderingContextBase::restoreUnpackParameters() |
6315 { | 6343 { |
6316 if (m_unpackAlignment != 1) | 6344 if (m_unpackAlignment != 1) |
6317 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); | 6345 contextGL()->PixelStorei(GL_UNPACK_ALIGNMENT, m_unpackAlignment); |
6318 } | 6346 } |
6319 | 6347 |
6320 } // namespace blink | 6348 } // namespace blink |
OLD | NEW |