OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 { | 1292 { |
1293 makeContextCurrent(); | 1293 makeContextCurrent(); |
1294 if (glGenerateMipmapEXT) { | 1294 if (glGenerateMipmapEXT) { |
1295 glGenerateMipmapEXT(target); | 1295 glGenerateMipmapEXT(target); |
1296 } | 1296 } |
1297 // FIXME: provide alternative code path? This will be unpleasant | 1297 // FIXME: provide alternative code path? This will be unpleasant |
1298 // to implement if glGenerateMipmapEXT is not available -- it will | 1298 // to implement if glGenerateMipmapEXT is not available -- it will |
1299 // require a texture readback and re-upload. | 1299 // require a texture readback and re-upload. |
1300 } | 1300 } |
1301 | 1301 |
1302 bool GraphicsContext3D::getActiveAttrib(CanvasProgram*, unsigned long, ActiveInfo&) | 1302 bool GraphicsContext3D::getActiveAttrib(CanvasProgram* program, unsigned long index, ActiveInfo& info) |
1303 { | 1303 { |
1304 // FIXME: implement. | 1304 if (!program) |
1305 notImplemented(); | 1305 return false; |
1306 return false; | 1306 GLint numActiveAttribs = -1; |
| 1307 glGetProgramiv(EXTRACT(program), GL_ACTIVE_ATTRIBUTES, &numActiveAttribs); |
| 1308 if (numActiveAttribs < 0) |
| 1309 return false; |
| 1310 if (index >= static_cast<GLuint>(numActiveAttribs)) |
| 1311 return false; |
| 1312 GLint maxNameLength = -1; |
| 1313 glGetProgramiv(EXTRACT(program), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxNameLength); |
| 1314 if (maxNameLength < 0) |
| 1315 return false; |
| 1316 GLchar* name = NULL; |
| 1317 if (!tryFastMalloc(maxNameLength * sizeof(GLchar)).getValue(name)) |
| 1318 return false; |
| 1319 GLsizei length = 0; |
| 1320 GLint size = -1; |
| 1321 GLenum type = 0; |
| 1322 glGetActiveAttrib(EXTRACT(program), index, maxNameLength, |
| 1323 &length, &size, &type, name); |
| 1324 if (size < 0) { |
| 1325 fastFree(name); |
| 1326 return false; |
| 1327 } |
| 1328 info.name = String(name, length); |
| 1329 info.type = type; |
| 1330 info.size = size; |
| 1331 fastFree(name); |
| 1332 return true; |
1307 } | 1333 } |
1308 | 1334 |
1309 bool GraphicsContext3D::getActiveUniform(CanvasProgram*, unsigned long, ActiveInfo&) | 1335 bool GraphicsContext3D::getActiveUniform(CanvasProgram* program, unsigned long index, ActiveInfo& info) |
1310 { | 1336 { |
1311 // FIXME: implement. | 1337 if (!program) |
1312 notImplemented(); | 1338 return false; |
1313 return false; | 1339 GLint numActiveUniforms = -1; |
| 1340 glGetProgramiv(EXTRACT(program), GL_ACTIVE_UNIFORMS, &numActiveUniforms); |
| 1341 if (numActiveUniforms < 0) |
| 1342 return false; |
| 1343 if (index >= static_cast<GLuint>(numActiveUniforms)) |
| 1344 return false; |
| 1345 GLint maxNameLength = -1; |
| 1346 glGetProgramiv(EXTRACT(program), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxNameLength); |
| 1347 if (maxNameLength < 0) |
| 1348 return false; |
| 1349 GLchar* name = NULL; |
| 1350 if (!tryFastMalloc(maxNameLength * sizeof(GLchar)).getValue(name)) |
| 1351 return false; |
| 1352 GLsizei length = 0; |
| 1353 GLint size = -1; |
| 1354 GLenum type = 0; |
| 1355 glGetActiveUniform(EXTRACT(program), index, maxNameLength, |
| 1356 &length, &size, &type, name); |
| 1357 if (size < 0) { |
| 1358 fastFree(name); |
| 1359 return false; |
| 1360 } |
| 1361 info.name = String(name, length); |
| 1362 info.type = type; |
| 1363 info.size = size; |
| 1364 fastFree(name); |
| 1365 return true; |
1314 } | 1366 } |
1315 | 1367 |
1316 int GraphicsContext3D::getAttribLocation(CanvasProgram* program, const String& name) | 1368 int GraphicsContext3D::getAttribLocation(CanvasProgram* program, const String& name) |
1317 { | 1369 { |
1318 if (!program) | 1370 if (!program) |
1319 return -1; | 1371 return -1; |
1320 | 1372 |
1321 makeContextCurrent(); | 1373 makeContextCurrent(); |
1322 return glGetAttribLocation(EXTRACT(program), name.utf8().data()); | 1374 return glGetAttribLocation(EXTRACT(program), name.utf8().data()); |
1323 } | 1375 } |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 GLint logLength; | 1486 GLint logLength; |
1435 glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &logLength); | 1487 glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &logLength); |
1436 if (logLength == 0) | 1488 if (logLength == 0) |
1437 return String(); | 1489 return String(); |
1438 GLchar* log = NULL; | 1490 GLchar* log = NULL; |
1439 if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log)) | 1491 if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log)) |
1440 return String(); | 1492 return String(); |
1441 GLsizei returnedLogLength; | 1493 GLsizei returnedLogLength; |
1442 glGetProgramInfoLog(programID, logLength, &returnedLogLength, log); | 1494 glGetProgramInfoLog(programID, logLength, &returnedLogLength, log); |
1443 ASSERT(logLength == returnedLogLength + 1); | 1495 ASSERT(logLength == returnedLogLength + 1); |
1444 String res = String::fromUTF8(log, returnedLogLength); | 1496 String res = String(log, returnedLogLength); |
1445 fastFree(log); | 1497 fastFree(log); |
1446 return res; | 1498 return res; |
1447 } | 1499 } |
1448 | 1500 |
1449 int GraphicsContext3D::getRenderbufferParameteri(unsigned long target, | 1501 int GraphicsContext3D::getRenderbufferParameteri(unsigned long target, |
1450 unsigned long pname) | 1502 unsigned long pname) |
1451 { | 1503 { |
1452 makeContextCurrent(); | 1504 makeContextCurrent(); |
1453 GLint param; | 1505 GLint param; |
1454 glGetRenderbufferParameteriv(target, pname, ¶m); | 1506 glGetRenderbufferParameteriv(target, pname, ¶m); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 GLint logLength; | 1539 GLint logLength; |
1488 glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &logLength); | 1540 glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &logLength); |
1489 if (logLength == 0) | 1541 if (logLength == 0) |
1490 return String(); | 1542 return String(); |
1491 GLchar* log = NULL; | 1543 GLchar* log = NULL; |
1492 if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log)) | 1544 if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log)) |
1493 return String(); | 1545 return String(); |
1494 GLsizei returnedLogLength; | 1546 GLsizei returnedLogLength; |
1495 glGetShaderInfoLog(shaderID, logLength, &returnedLogLength, log); | 1547 glGetShaderInfoLog(shaderID, logLength, &returnedLogLength, log); |
1496 ASSERT(logLength == returnedLogLength + 1); | 1548 ASSERT(logLength == returnedLogLength + 1); |
1497 String res = String::fromUTF8(log, returnedLogLength); | 1549 String res = String(log, returnedLogLength); |
1498 fastFree(log); | 1550 fastFree(log); |
1499 return res; | 1551 return res; |
1500 } | 1552 } |
1501 | 1553 |
1502 String GraphicsContext3D::getShaderSource(CanvasShader* shader) | 1554 String GraphicsContext3D::getShaderSource(CanvasShader* shader) |
1503 { | 1555 { |
1504 makeContextCurrent(); | 1556 makeContextCurrent(); |
1505 GLuint shaderID = EXTRACT(shader); | 1557 GLuint shaderID = EXTRACT(shader); |
1506 GLint logLength; | 1558 GLint logLength; |
1507 glGetShaderiv(shaderID, GL_SHADER_SOURCE_LENGTH, &logLength); | 1559 glGetShaderiv(shaderID, GL_SHADER_SOURCE_LENGTH, &logLength); |
1508 if (logLength == 0) | 1560 if (logLength == 0) |
1509 return String(); | 1561 return String(); |
1510 GLchar* log = NULL; | 1562 GLchar* log = NULL; |
1511 if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log)) | 1563 if (!tryFastMalloc(logLength * sizeof(GLchar)).getValue(log)) |
1512 return String(); | 1564 return String(); |
1513 GLsizei returnedLogLength; | 1565 GLsizei returnedLogLength; |
1514 glGetShaderSource(shaderID, logLength, &returnedLogLength, log); | 1566 glGetShaderSource(shaderID, logLength, &returnedLogLength, log); |
1515 ASSERT(logLength == returnedLogLength + 1); | 1567 ASSERT(logLength == returnedLogLength + 1); |
1516 String res = String::fromUTF8(log, returnedLogLength); | 1568 String res = String(log, returnedLogLength); |
1517 fastFree(log); | 1569 fastFree(log); |
1518 return res; | 1570 return res; |
1519 } | 1571 } |
1520 | 1572 |
1521 String GraphicsContext3D::getString(unsigned long name) | 1573 String GraphicsContext3D::getString(unsigned long name) |
1522 { | 1574 { |
1523 makeContextCurrent(); | 1575 makeContextCurrent(); |
1524 return String::fromUTF8(reinterpret_cast<const char*>(glGetString(name))); | 1576 return String(reinterpret_cast<const char*>(glGetString(name))); |
1525 } | 1577 } |
1526 | 1578 |
1527 float GraphicsContext3D::getTexParameterf(unsigned long target, unsigned long pname) | 1579 float GraphicsContext3D::getTexParameterf(unsigned long target, unsigned long pname) |
1528 { | 1580 { |
1529 makeContextCurrent(); | 1581 makeContextCurrent(); |
1530 if (!m_internal->validateTextureTarget(target)) { | 1582 if (!m_internal->validateTextureTarget(target)) { |
1531 // FIXME: throw exception. | 1583 // FIXME: throw exception. |
1532 return 0; | 1584 return 0; |
1533 } | 1585 } |
1534 | 1586 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 // exception. | 1758 // exception. |
1707 return; | 1759 return; |
1708 } | 1760 } |
1709 | 1761 |
1710 makeContextCurrent(); | 1762 makeContextCurrent(); |
1711 glPixelStorei(pname, param); | 1763 glPixelStorei(pname, param); |
1712 } | 1764 } |
1713 | 1765 |
1714 GL_SAME_METHOD_2(PolygonOffset, polygonOffset, double, double) | 1766 GL_SAME_METHOD_2(PolygonOffset, polygonOffset, double, double) |
1715 | 1767 |
| 1768 PassRefPtr<CanvasArray> GraphicsContext3D::readPixels(long x, long y, |
| 1769 unsigned long width, unsigned long height, |
| 1770 unsigned long format, unsigned long type) { |
| 1771 // FIXME: support more pixel formats and types. |
| 1772 if (!((format == GL_RGBA) && (type == GL_UNSIGNED_BYTE))) { |
| 1773 return 0; |
| 1774 } |
| 1775 |
| 1776 // FIXME: take into account pack alignment. |
| 1777 RefPtr<CanvasUnsignedByteArray> array = CanvasUnsignedByteArray::create(width * height * 4); |
| 1778 glReadPixels(x, y, width, height, format, type, array->baseAddress()); |
| 1779 return array; |
| 1780 } |
| 1781 |
1716 void GraphicsContext3D::releaseShaderCompiler() | 1782 void GraphicsContext3D::releaseShaderCompiler() |
1717 { | 1783 { |
1718 } | 1784 } |
1719 | 1785 |
1720 GL_SAME_METHOD_4(RenderbufferStorage, renderbufferStorage, unsigned long, unsigned long, unsigned long, unsigned long) | 1786 GL_SAME_METHOD_4(RenderbufferStorage, renderbufferStorage, unsigned long, unsigned long, unsigned long, unsigned long) |
1721 | 1787 |
1722 GL_SAME_METHOD_2(SampleCoverage, sampleCoverage, double, bool) | 1788 GL_SAME_METHOD_2(SampleCoverage, sampleCoverage, double, bool) |
1723 | 1789 |
1724 GL_SAME_METHOD_4(Scissor, scissor, long, long, unsigned long, unsigned long) | 1790 GL_SAME_METHOD_4(Scissor, scissor, long, long, unsigned long, unsigned long) |
1725 | 1791 |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 | 2247 |
2182 void GraphicsContext3D::viewport(long x, long y, unsigned long width, unsigned long height) | 2248 void GraphicsContext3D::viewport(long x, long y, unsigned long width, unsigned long height) |
2183 { | 2249 { |
2184 makeContextCurrent(); | 2250 makeContextCurrent(); |
2185 m_internal->viewportImpl(x, y, width, height); | 2251 m_internal->viewportImpl(x, y, width, height); |
2186 } | 2252 } |
2187 | 2253 |
2188 } | 2254 } |
2189 | 2255 |
2190 #endif // ENABLE(3D_CANVAS) | 2256 #endif // ENABLE(3D_CANVAS) |
OLD | NEW |