Changeset 152351 in webkit


Ignore:
Timestamp:
Jul 3, 2013 5:59:55 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

TextureUnit code optimization
https://bugs.webkit.org/show_bug.cgi?id=117868

Patch by Przemyslaw Szymanski <p.szymanski3@samsung.com> on 2013-07-03
Reviewed by Noam Rosenthal.

According to OpenGL ES 2.0 specification it is not possible to use both
texture2D and textureCubeMap in one texture unit.
This patch reduces amount of code, slightly increases rendering performance
and makes WebKit more consistent with OpenGL.

No new tests. Covered by existing tests:
LayoutTests/webgl/conformance/textures/tex-image-webgl.html
LayoutTests/webgl/conformance/textures/texture-complete.html

  • html/canvas/WebGLRenderingContext.cpp:

(WebCore::WebGLRenderingContext::~WebGLRenderingContext):
(WebCore::WebGLRenderingContext::reshape):
(WebCore::WebGLRenderingContext::bindTexture):
(WebCore::WebGLRenderingContext::deleteTexture):
(WebCore::WebGLRenderingContext::getParameter):
(WebCore::WebGLRenderingContext::handleNPOTTextures):
(WebCore::WebGLRenderingContext::validateTextureBinding):
(WebCore::WebGLRenderingContext::restoreCurrentTexture2D):

  • html/canvas/WebGLRenderingContext.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r152350 r152351  
     12013-07-03  Przemyslaw Szymanski  <p.szymanski3@samsung.com>
     2
     3        TextureUnit code optimization
     4        https://bugs.webkit.org/show_bug.cgi?id=117868
     5
     6        Reviewed by Noam Rosenthal.
     7
     8        According to OpenGL ES 2.0 specification it is not possible to use both
     9        texture2D and textureCubeMap in one texture unit.
     10        This patch reduces amount of code, slightly increases rendering performance
     11        and makes WebKit more consistent with OpenGL.
     12
     13        No new tests. Covered by existing tests:
     14        LayoutTests/webgl/conformance/textures/tex-image-webgl.html
     15        LayoutTests/webgl/conformance/textures/texture-complete.html
     16
     17        * html/canvas/WebGLRenderingContext.cpp:
     18        (WebCore::WebGLRenderingContext::~WebGLRenderingContext):
     19        (WebCore::WebGLRenderingContext::reshape):
     20        (WebCore::WebGLRenderingContext::bindTexture):
     21        (WebCore::WebGLRenderingContext::deleteTexture):
     22        (WebCore::WebGLRenderingContext::getParameter):
     23        (WebCore::WebGLRenderingContext::handleNPOTTextures):
     24        (WebCore::WebGLRenderingContext::validateTextureBinding):
     25        (WebCore::WebGLRenderingContext::restoreCurrentTexture2D):
     26        * html/canvas/WebGLRenderingContext.h:
     27
    1282013-07-03  Christophe Dumez  <ch.dumez@sisa.samsung.com>
    229
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp

    r151947 r152351  
    608608    m_renderbufferBinding = 0;
    609609
    610     for (size_t i = 0; i < m_textureUnits.size(); ++i) {
    611       m_textureUnits[i].m_texture2DBinding = 0;
    612       m_textureUnits[i].m_textureCubeMapBinding = 0;
    613     }
     610    for (size_t i = 0; i < m_textureUnits.size(); ++i)
     611        m_textureUnits[i].m_textureBinding = 0;
    614612
    615613    m_blackTexture2D = 0;
     
    817815        m_context->reshape(width, height);
    818816
    819     m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZero(m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get()));
     817    m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZero(m_textureUnits[m_activeTextureUnit].m_textureBinding.get()));
    820818    m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, objectOrZero(m_renderbufferBinding.get()));
    821819    if (m_framebufferBinding)
     
    10151013    GC3Dint maxLevel = 0;
    10161014    if (target == GraphicsContext3D::TEXTURE_2D) {
    1017         m_textureUnits[m_activeTextureUnit].m_texture2DBinding = texture;
     1015        m_textureUnits[m_activeTextureUnit].m_textureBinding = texture;
    10181016        maxLevel = m_maxTextureLevel;
    10191017
     
    10221020
    10231021    } else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP) {
    1024         m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding = texture;
     1022        m_textureUnits[m_activeTextureUnit].m_textureBinding = texture;
    10251023        maxLevel = m_maxCubeMapTextureLevel;
    10261024    } else {
     
    16361634        return;
    16371635    for (size_t i = 0; i < m_textureUnits.size(); ++i) {
    1638         if (texture == m_textureUnits[i].m_texture2DBinding)
    1639             m_textureUnits[i].m_texture2DBinding = 0;
    1640         if (texture == m_textureUnits[i].m_textureCubeMapBinding)
    1641             m_textureUnits[i].m_textureCubeMapBinding = 0;
     1636        if (texture == m_textureUnits[i].m_textureBinding)
     1637            m_textureUnits[i].m_textureBinding = 0;
    16421638    }
    16431639    if (m_framebufferBinding)
     
    26932689        return getIntParameter(pname);
    26942690    case GraphicsContext3D::TEXTURE_BINDING_2D:
    2695         return WebGLGetInfo(PassRefPtr<WebGLTexture>(m_textureUnits[m_activeTextureUnit].m_texture2DBinding));
     2691        return WebGLGetInfo(PassRefPtr<WebGLTexture>(m_textureUnits[m_activeTextureUnit].m_textureBinding));
    26962692    case GraphicsContext3D::TEXTURE_BINDING_CUBE_MAP:
    2697         return WebGLGetInfo(PassRefPtr<WebGLTexture>(m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding));
     2693        return WebGLGetInfo(PassRefPtr<WebGLTexture>(m_textureUnits[m_activeTextureUnit].m_textureBinding));
    26982694    case GraphicsContext3D::UNPACK_ALIGNMENT:
    26992695        return getIntParameter(pname);
     
    48034799    bool resetActiveUnit = false;
    48044800    for (unsigned ii = 0; ii < m_textureUnits.size(); ++ii) {
    4805         if ((m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_texture2DBinding->needToUseBlackTexture())
    4806             || (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii].m_textureCubeMapBinding->needToUseBlackTexture())) {
     4801        if (m_textureUnits[ii].m_textureBinding && m_textureUnits[ii].m_textureBinding->needToUseBlackTexture()) {
    48074802            if (ii != m_activeTextureUnit) {
    48084803                m_context->activeTexture(ii);
     
    48124807                resetActiveUnit = false;
    48134808            }
    4814             WebGLTexture* tex2D;
    4815             WebGLTexture* texCubeMap;
     4809            WebGLTexture* texture = 0;
     4810            GC3Denum target = m_textureUnits[ii].m_textureBinding->getTarget();
    48164811            if (prepareToDraw) {
    48174812                String msg(String("texture bound to texture unit ") + String::number(ii)
    48184813                    + " is not renderable. It maybe non-power-of-2 and have incompatible texture filtering or is not 'texture complete'");
    48194814                printGLWarningToConsole(functionName, msg.utf8().data());
    4820                 tex2D = m_blackTexture2D.get();
    4821                 texCubeMap = m_blackTextureCubeMap.get();
    4822             } else {
    4823                 tex2D = m_textureUnits[ii].m_texture2DBinding.get();
    4824                 texCubeMap = m_textureUnits[ii].m_textureCubeMapBinding.get();
    4825             }
    4826             if (m_textureUnits[ii].m_texture2DBinding && m_textureUnits[ii].m_texture2DBinding->needToUseBlackTexture())
    4827                 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, objectOrZero(tex2D));
    4828             if (m_textureUnits[ii].m_textureCubeMapBinding && m_textureUnits[ii].m_textureCubeMapBinding->needToUseBlackTexture())
    4829                 m_context->bindTexture(GraphicsContext3D::TEXTURE_CUBE_MAP, objectOrZero(texCubeMap));
     4815                if (target == GraphicsContext3D::TEXTURE_2D)
     4816                    texture = m_blackTexture2D.get();
     4817                else if (target == GraphicsContext3D::TEXTURE_CUBE_MAP)
     4818                    texture = m_blackTextureCubeMap.get();
     4819            } else
     4820                texture = m_textureUnits[ii].m_textureBinding.get();
     4821            m_context->bindTexture(target, objectOrZero(texture));
    48304822        }
    48314823    }
     
    48924884WebGLTexture* WebGLRenderingContext::validateTextureBinding(const char* functionName, GC3Denum target, bool useSixEnumsForCubeMap)
    48934885{
    4894     WebGLTexture* tex = 0;
    48954886    switch (target) {
    48964887    case GraphicsContext3D::TEXTURE_2D:
    4897         tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get();
    48984888        break;
    48994889    case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X:
     
    49074897            return 0;
    49084898        }
    4909         tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding.get();
    49104899        break;
    49114900    case GraphicsContext3D::TEXTURE_CUBE_MAP:
     
    49144903            return 0;
    49154904        }
    4916         tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding.get();
    49174905        break;
    49184906    default:
     
    49204908        return 0;
    49214909    }
     4910    WebGLTexture* tex = m_textureUnits[m_activeTextureUnit].m_textureBinding.get();
    49224911    if (!tex)
    49234912        synthesizeGLError(GraphicsContext3D::INVALID_OPERATION, functionName, "no texture");
     
    60306019{
    60316020    ExceptionCode ec;
    6032     bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_texture2DBinding.get(), ec);
     6021    bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureUnits[m_activeTextureUnit].m_textureBinding.get(), ec);
    60336022}
    60346023
  • trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h

    r151947 r152351  
    450450    RefPtr<WebGLFramebuffer> m_framebufferBinding;
    451451    RefPtr<WebGLRenderbuffer> m_renderbufferBinding;
    452     class TextureUnitState {
    453     public:
    454         RefPtr<WebGLTexture> m_texture2DBinding;
    455         RefPtr<WebGLTexture> m_textureCubeMapBinding;
     452    struct TextureUnitState {
     453        RefPtr<WebGLTexture> m_textureBinding;
    456454    };
    457455    Vector<TextureUnitState> m_textureUnits;
Note: See TracChangeset for help on using the changeset viewer.