Changeset 66781 in webkit


Ignore:
Timestamp:
Sep 3, 2010 5:49:40 PM (14 years ago)
Author:
cmarrin@apple.com
Message:

2010-09-03 Paul Sawaya <psawaya@apple.com>

Reviewed by Chris Marrin.

Refactored out Mac specific code for platform/graphics/mac/GraphicsContext3D.mm file.
Left general OpenGL code in platform/graphics/GraphicsContext3DOpenGL.cpp.
https://bugs.webkit.org/show_bug.cgi?id=30625

Location:
trunk/WebCore
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r66780 r66781  
     12010-09-03  Paul Sawaya  <psawaya@apple.com>
     2
     3        Reviewed by Chris Marrin.
     4
     5        Refactored out Mac specific code for platform/graphics/mac/GraphicsContext3D.mm file.
     6        Left general OpenGL code in platform/graphics/GraphicsContext3DOpenGL.cpp.
     7        https://bugs.webkit.org/show_bug.cgi?id=30625
     8
     9        * WebCore.gypi:
     10        * WebCore.xcodeproj/project.pbxproj:
     11        * html/canvas/WebGLObject.cpp:
     12        (WebCore::WebGLObject::deleteObject):
     13        * platform/graphics/ANGLEWebKitBridge.h:
     14        * platform/graphics/GraphicsContext3D.h:
     15        * platform/graphics/GraphicsContext3DOpenGL.cpp: Copied from platform/graphics/mac/GraphicsContext3DMac.mm.
     16        (WebCore::GraphicsContext3D::prepareTexture):
     17        (WebCore::GraphicsContext3D::activeTexture):
     18        (WebCore::GraphicsContext3D::attachShader):
     19        (WebCore::GraphicsContext3D::bindAttribLocation):
     20        (WebCore::GraphicsContext3D::bindBuffer):
     21        (WebCore::GraphicsContext3D::bindFramebuffer):
     22        (WebCore::GraphicsContext3D::bindRenderbuffer):
     23        (WebCore::GraphicsContext3D::bindTexture):
     24        (WebCore::GraphicsContext3D::blendColor):
     25        (WebCore::GraphicsContext3D::blendEquation):
     26        (WebCore::GraphicsContext3D::blendEquationSeparate):
     27        (WebCore::GraphicsContext3D::blendFunc):
     28        (WebCore::GraphicsContext3D::blendFuncSeparate):
     29        (WebCore::GraphicsContext3D::bufferData):
     30        (WebCore::GraphicsContext3D::bufferSubData):
     31        (WebCore::GraphicsContext3D::checkFramebufferStatus):
     32        (WebCore::GraphicsContext3D::clearColor):
     33        (WebCore::GraphicsContext3D::clear):
     34        (WebCore::GraphicsContext3D::clearDepth):
     35        (WebCore::GraphicsContext3D::clearStencil):
     36        (WebCore::GraphicsContext3D::colorMask):
     37        (WebCore::GraphicsContext3D::compileShader):
     38        (WebCore::GraphicsContext3D::copyTexImage2D):
     39        (WebCore::GraphicsContext3D::copyTexSubImage2D):
     40        (WebCore::GraphicsContext3D::cullFace):
     41        (WebCore::GraphicsContext3D::depthFunc):
     42        (WebCore::GraphicsContext3D::depthMask):
     43        (WebCore::GraphicsContext3D::depthRange):
     44        (WebCore::GraphicsContext3D::detachShader):
     45        (WebCore::GraphicsContext3D::disable):
     46        (WebCore::GraphicsContext3D::disableVertexAttribArray):
     47        (WebCore::GraphicsContext3D::drawArrays):
     48        (WebCore::GraphicsContext3D::drawElements):
     49        (WebCore::GraphicsContext3D::enable):
     50        (WebCore::GraphicsContext3D::enableVertexAttribArray):
     51        (WebCore::GraphicsContext3D::finish):
     52        (WebCore::GraphicsContext3D::flush):
     53        (WebCore::GraphicsContext3D::framebufferRenderbuffer):
     54        (WebCore::GraphicsContext3D::framebufferTexture2D):
     55        (WebCore::GraphicsContext3D::frontFace):
     56        (WebCore::GraphicsContext3D::generateMipmap):
     57        (WebCore::GraphicsContext3D::getActiveAttrib):
     58        (WebCore::GraphicsContext3D::getActiveUniform):
     59        (WebCore::GraphicsContext3D::getAttachedShaders):
     60        (WebCore::GraphicsContext3D::getAttribLocation):
     61        (WebCore::GraphicsContext3D::getError):
     62        (WebCore::GraphicsContext3D::getString):
     63        (WebCore::GraphicsContext3D::hint):
     64        (WebCore::GraphicsContext3D::isBuffer):
     65        (WebCore::GraphicsContext3D::isEnabled):
     66        (WebCore::GraphicsContext3D::isFramebuffer):
     67        (WebCore::GraphicsContext3D::isProgram):
     68        (WebCore::GraphicsContext3D::isRenderbuffer):
     69        (WebCore::GraphicsContext3D::isShader):
     70        (WebCore::GraphicsContext3D::isTexture):
     71        (WebCore::GraphicsContext3D::lineWidth):
     72        (WebCore::GraphicsContext3D::linkProgram):
     73        (WebCore::GraphicsContext3D::pixelStorei):
     74        (WebCore::GraphicsContext3D::polygonOffset):
     75        (WebCore::GraphicsContext3D::readPixels):
     76        (WebCore::GraphicsContext3D::releaseShaderCompiler):
     77        (WebCore::GraphicsContext3D::renderbufferStorage):
     78        (WebCore::GraphicsContext3D::sampleCoverage):
     79        (WebCore::GraphicsContext3D::scissor):
     80        (WebCore::GraphicsContext3D::shaderSource):
     81        (WebCore::GraphicsContext3D::stencilFunc):
     82        (WebCore::GraphicsContext3D::stencilFuncSeparate):
     83        (WebCore::GraphicsContext3D::stencilMask):
     84        (WebCore::GraphicsContext3D::stencilMaskSeparate):
     85        (WebCore::GraphicsContext3D::stencilOp):
     86        (WebCore::GraphicsContext3D::stencilOpSeparate):
     87        (WebCore::GraphicsContext3D::texParameterf):
     88        (WebCore::GraphicsContext3D::texParameteri):
     89        (WebCore::GraphicsContext3D::uniform1f):
     90        (WebCore::GraphicsContext3D::uniform1fv):
     91        (WebCore::GraphicsContext3D::uniform2f):
     92        (WebCore::GraphicsContext3D::uniform2fv):
     93        (WebCore::GraphicsContext3D::uniform3f):
     94        (WebCore::GraphicsContext3D::uniform3fv):
     95        (WebCore::GraphicsContext3D::uniform4f):
     96        (WebCore::GraphicsContext3D::uniform4fv):
     97        (WebCore::GraphicsContext3D::uniform1i):
     98        (WebCore::GraphicsContext3D::uniform1iv):
     99        (WebCore::GraphicsContext3D::uniform2i):
     100        (WebCore::GraphicsContext3D::uniform2iv):
     101        (WebCore::GraphicsContext3D::uniform3i):
     102        (WebCore::GraphicsContext3D::uniform3iv):
     103        (WebCore::GraphicsContext3D::uniform4i):
     104        (WebCore::GraphicsContext3D::uniform4iv):
     105        (WebCore::GraphicsContext3D::uniformMatrix2fv):
     106        (WebCore::GraphicsContext3D::uniformMatrix3fv):
     107        (WebCore::GraphicsContext3D::uniformMatrix4fv):
     108        (WebCore::GraphicsContext3D::useProgram):
     109        (WebCore::GraphicsContext3D::validateProgram):
     110        (WebCore::GraphicsContext3D::vertexAttrib1f):
     111        (WebCore::GraphicsContext3D::vertexAttrib1fv):
     112        (WebCore::GraphicsContext3D::vertexAttrib2f):
     113        (WebCore::GraphicsContext3D::vertexAttrib2fv):
     114        (WebCore::GraphicsContext3D::vertexAttrib3f):
     115        (WebCore::GraphicsContext3D::vertexAttrib3fv):
     116        (WebCore::GraphicsContext3D::vertexAttrib4f):
     117        (WebCore::GraphicsContext3D::vertexAttrib4fv):
     118        (WebCore::GraphicsContext3D::vertexAttribPointer):
     119        (WebCore::GraphicsContext3D::viewport):
     120        (WebCore::GraphicsContext3D::getBooleanv):
     121        (WebCore::GraphicsContext3D::getBufferParameteriv):
     122        (WebCore::GraphicsContext3D::getFloatv):
     123        (WebCore::GraphicsContext3D::getFramebufferAttachmentParameteriv):
     124        (WebCore::GraphicsContext3D::getIntegerv):
     125        (WebCore::GraphicsContext3D::getProgramiv):
     126        (WebCore::GraphicsContext3D::getProgramInfoLog):
     127        (WebCore::GraphicsContext3D::getRenderbufferParameteriv):
     128        (WebCore::GraphicsContext3D::getShaderiv):
     129        (WebCore::GraphicsContext3D::getShaderInfoLog):
     130        (WebCore::GraphicsContext3D::getShaderSource):
     131        (WebCore::GraphicsContext3D::getTexParameterfv):
     132        (WebCore::GraphicsContext3D::getTexParameteriv):
     133        (WebCore::GraphicsContext3D::getUniformfv):
     134        (WebCore::GraphicsContext3D::getUniformiv):
     135        (WebCore::GraphicsContext3D::getUniformLocation):
     136        (WebCore::GraphicsContext3D::getVertexAttribfv):
     137        (WebCore::GraphicsContext3D::getVertexAttribiv):
     138        (WebCore::GraphicsContext3D::getVertexAttribOffset):
     139        (WebCore::GraphicsContext3D::texImage2D):
     140        (WebCore::GraphicsContext3D::texSubImage2D):
     141        (WebCore::GraphicsContext3D::createBuffer):
     142        (WebCore::GraphicsContext3D::createFramebuffer):
     143        (WebCore::GraphicsContext3D::createProgram):
     144        (WebCore::GraphicsContext3D::createRenderbuffer):
     145        (WebCore::GraphicsContext3D::createShader):
     146        (WebCore::GraphicsContext3D::createTexture):
     147        (WebCore::GraphicsContext3D::deleteBuffer):
     148        (WebCore::GraphicsContext3D::deleteFramebuffer):
     149        (WebCore::GraphicsContext3D::deleteProgram):
     150        (WebCore::GraphicsContext3D::deleteRenderbuffer):
     151        (WebCore::GraphicsContext3D::deleteShader):
     152        (WebCore::GraphicsContext3D::deleteTexture):
     153        * platform/graphics/mac/GraphicsContext3DMac.mm:
     154        (WebCore::GraphicsContext3D::ensureContext):
     155        (WebCore::GraphicsContext3D::isErrorGeneratedOnOutOfBoundsAccesses):
     156
    11572010-09-03  James Robinson  <jamesr@chromium.org>
    2158
  • trunk/WebCore/WebCore.gypi

    r66779 r66781  
    26002600            'platform/graphics/GraphicsContext.h',
    26012601            'platform/graphics/GraphicsContext3D.cpp',
     2602            'platform/graphics/GraphicsContext3DOpenGL.cpp',
    26022603            'platform/graphics/GraphicsContext3D.h',
    26032604            'platform/graphics/GraphicsContextPrivate.h',
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r66774 r66781  
    53705370                FAC12CC41120DA6900DACC36 /* RenderMathMLSubSup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAC12CC21120DA6900DACC36 /* RenderMathMLSubSup.cpp */; };
    53715371                FAC12CC51120DA6900DACC36 /* RenderMathMLSubSup.h in Headers */ = {isa = PBXBuildFile; fileRef = FAC12CC31120DA6900DACC36 /* RenderMathMLSubSup.h */; };
     5372                FB58CB79122F153800878851 /* GraphicsContext3DOpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FB58CAEA1228586500878851 /* GraphicsContext3DOpenGL.cpp */; };
    53725373                FE6FD4880F676E5700092873 /* Coordinates.h in Headers */ = {isa = PBXBuildFile; fileRef = FE6FD4850F676E5700092873 /* Coordinates.h */; settings = {ATTRIBUTES = (Private, ); }; };
    53735374                FE6FD48D0F676E9300092873 /* JSCoordinates.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE6FD48B0F676E9300092873 /* JSCoordinates.cpp */; };
     
    1124111242                FAC12CC21120DA6900DACC36 /* RenderMathMLSubSup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderMathMLSubSup.cpp; sourceTree = "<group>"; };
    1124211243                FAC12CC31120DA6900DACC36 /* RenderMathMLSubSup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMathMLSubSup.h; sourceTree = "<group>"; };
     11244                FB58CAEA1228586500878851 /* GraphicsContext3DOpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsContext3DOpenGL.cpp; sourceTree = "<group>"; };
    1124311245                FE49EF970DC51462004266E1 /* DashboardSupportCSSPropertyNames.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DashboardSupportCSSPropertyNames.in; sourceTree = "<group>"; };
    1124411246                FE6FD4850F676E5700092873 /* Coordinates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Coordinates.h; sourceTree = "<group>"; };
     
    1591215914                                6E21C6BF1126338500A7BE02 /* GraphicsContext3D.cpp */,
    1591315915                                49C7B9FB1042D3650009D447 /* GraphicsContext3D.h */,
     15916                                FB58CAEA1228586500878851 /* GraphicsContext3DOpenGL.cpp */,
    1591415917                                A88FE3330E5EEE87008D8C0F /* GraphicsContextPrivate.h */,
    1591515918                                0F580B090F12A2690051D689 /* GraphicsLayer.cpp */,
     
    2049220495                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
    2049320496                        compatibilityVersion = "Xcode 2.4";
     20497                        developmentRegion = English;
    2049420498                        hasScannedForEncodings = 1;
    2049520499                        knownRegions = (
     
    2289622900                                898785F0122E1E87003AABDA /* JSFileException.cpp in Sources */,
    2289722901                                898785F4122E1EAC003AABDA /* JSFileReaderSync.cpp in Sources */,
     22902                                FB58CB79122F153800878851 /* GraphicsContext3DOpenGL.cpp in Sources */,
    2289822903                        );
    2289922904                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/WebCore/html/canvas/WebGLObject.cpp

    r65330 r66781  
    6161    if (m_object) {
    6262        if (m_context) {
    63             m_context->graphicsContext3D()->makeContextCurrent();
     63            m_context->graphicsContext3D()->ensureContext();
    6464            deleteObjectImpl(m_object);
    6565        }
  • trunk/WebCore/platform/graphics/ANGLEWebKitBridge.h

    r65446 r66781  
    3939};
    4040
     41
    4142class ANGLEWebKitBridge {
    4243public:
  • trunk/WebCore/platform/graphics/GraphicsContext3D.h

    r66055 r66781  
    452452#endif
    453453#endif
    454     void makeContextCurrent();
     454    void ensureContext();
    455455
    456456#if PLATFORM(MAC) || PLATFORM(CHROMIUM)
  • trunk/WebCore/platform/graphics/GraphicsContext3DOpenGL.cpp

    r66758 r66781  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030#include "GraphicsContext3D.h"
    3131
    32 #import "BlockExceptions.h"
    33 
    3432#include "ArrayBuffer.h"
    3533#include "ArrayBufferView.h"
    36 #include "WebGLObject.h"
    3734#include "CanvasRenderingContext.h"
    3835#include "Float32Array.h"
     
    4340#include "NotImplemented.h"
    4441#include "Uint8Array.h"
    45 #include "WebGLLayer.h"
    46 #include <CoreGraphics/CGBitmapContext.h>
     42#include "WebGLObject.h"
     43
     44#if PLATFORM(MAC)
    4745#include <OpenGL/CGLRenderers.h>
    4846#include <OpenGL/gl.h>
     47#endif
     48
    4949#include <wtf/UnusedParam.h>
    5050#include <wtf/text/CString.h>
    5151
    5252namespace WebCore {
    53 
    54 static void setPixelFormat(Vector<CGLPixelFormatAttribute>& attribs, int colorBits, int depthBits, bool accelerated, bool supersample, bool closest)
    55 {
    56     attribs.clear();
    57    
    58     attribs.append(kCGLPFAColorSize);
    59     attribs.append(static_cast<CGLPixelFormatAttribute>(colorBits));
    60     attribs.append(kCGLPFADepthSize);
    61     attribs.append(static_cast<CGLPixelFormatAttribute>(depthBits));
    62    
    63     if (accelerated)
    64         attribs.append(kCGLPFAAccelerated);
    65     else {
    66         attribs.append(kCGLPFARendererID);
    67         attribs.append(static_cast<CGLPixelFormatAttribute>(kCGLRendererGenericFloatID));
    68     }
    69        
    70     if (supersample)
    71         attribs.append(kCGLPFASupersample);
    72        
    73     if (closest)
    74         attribs.append(kCGLPFAClosestPolicy);
    75        
    76     attribs.append(static_cast<CGLPixelFormatAttribute>(0));
    77 }
    78 
    79 PassOwnPtr<GraphicsContext3D> GraphicsContext3D::create(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow)
    80 {
    81     OwnPtr<GraphicsContext3D> context(new GraphicsContext3D(attrs, hostWindow));
    82     return context->m_contextObj ? context.release() : 0;
    83 }
    84 
    85 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow)
    86     : m_currentWidth(0)
    87     , m_currentHeight(0)
    88     , m_attrs(attrs)
    89     , m_contextObj(0)
    90     , m_texture(0)
    91     , m_fbo(0)
    92     , m_depthStencilBuffer(0)
    93     , m_boundFBO(0)
    94     , m_multisampleFBO(0)
    95     , m_multisampleDepthStencilBuffer(0)
    96     , m_multisampleColorBuffer(0)
    97 {
    98     UNUSED_PARAM(hostWindow);
    99 
    100     Vector<CGLPixelFormatAttribute> attribs;
    101     CGLPixelFormatObj pixelFormatObj = 0;
    102     GLint numPixelFormats = 0;
    103    
    104     // We will try:
    105     //
    106     //  1) 32 bit RGBA/32 bit depth/accelerated/supersampled
    107     //  2) 32 bit RGBA/32 bit depth/accelerated
    108     //  3) 32 bit RGBA/16 bit depth/accelerated
    109     //  4) closest to 32 bit RGBA/16 bit depth/software renderer
    110     //
    111     //  If none of that works, we simply fail and set m_contextObj to 0.
    112    
    113     setPixelFormat(attribs, 32, 32, true, true, false);
    114     CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
    115     if (numPixelFormats == 0) {
    116         setPixelFormat(attribs, 32, 32, true, false, false);
    117         CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
    118        
    119         if (numPixelFormats == 0) {
    120             setPixelFormat(attribs, 32, 16, true, false, false);
    121             CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
    122        
    123             if (numPixelFormats == 0) {
    124                 setPixelFormat(attribs, 32, 16, false, false, true);
    125                 CGLChoosePixelFormat(attribs.data(), &pixelFormatObj, &numPixelFormats);
    126        
    127                 if (numPixelFormats == 0) {
    128                     // Could not find an acceptable renderer - fail
    129                     return;
    130                 }
    131             }
    132         }
    133     }
    134    
    135     CGLError err = CGLCreateContext(pixelFormatObj, 0, &m_contextObj);
    136     CGLDestroyPixelFormat(pixelFormatObj);
    137    
    138     if (err != kCGLNoError || !m_contextObj) {
    139         // Could not create the context - fail
    140         m_contextObj = 0;
    141         return;
    142     }
    143 
    144     // Set the current context to the one given to us.
    145     CGLSetCurrentContext(m_contextObj);
    146    
    147     validateAttributes();
    148 
    149     // Create the WebGLLayer
    150     BEGIN_BLOCK_OBJC_EXCEPTIONS
    151         m_webGLLayer.adoptNS([[WebGLLayer alloc] initWithGraphicsContext3D:this]);
    152 #ifndef NDEBUG
    153         [m_webGLLayer.get() setName:@"WebGL Layer"];
    154 #endif   
    155     END_BLOCK_OBJC_EXCEPTIONS
    156    
    157     // create a texture to render into
    158     ::glGenTextures(1, &m_texture);
    159     ::glBindTexture(GL_TEXTURE_2D, m_texture);
    160     ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    161     ::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    162     ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    163     ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    164     ::glBindTexture(GL_TEXTURE_2D, 0);
    165    
    166     // create an FBO
    167     ::glGenFramebuffersEXT(1, &m_fbo);
    168     ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    169    
    170     m_boundFBO = m_fbo;
    171     if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth))
    172         ::glGenRenderbuffersEXT(1, &m_depthStencilBuffer);
    173 
    174     // create an multisample FBO
    175     if (m_attrs.antialias) {
    176         ::glGenFramebuffersEXT(1, &m_multisampleFBO);
    177         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
    178         m_boundFBO = m_multisampleFBO;
    179         ::glGenRenderbuffersEXT(1, &m_multisampleColorBuffer);
    180         if (m_attrs.stencil || m_attrs.depth)
    181             ::glGenRenderbuffersEXT(1, &m_multisampleDepthStencilBuffer);
    182     }
    183    
    184     // ANGLE initialization.
    185 
    186     TBuiltInResource ANGLEResources;
    187 
    188     ANGLEResources.MaxVertexAttribs = 0;
    189     getIntegerv(GraphicsContext3D::MAX_VERTEX_ATTRIBS, &ANGLEResources.MaxVertexAttribs);
    190     ANGLEResources.MaxVertexUniformVectors = 0;
    191     getIntegerv(GraphicsContext3D::MAX_VERTEX_UNIFORM_VECTORS, &ANGLEResources.MaxVertexUniformVectors);
    192     ANGLEResources.MaxVaryingVectors = 0;
    193     getIntegerv(GraphicsContext3D::MAX_VARYING_VECTORS, &ANGLEResources.MaxVaryingVectors);
    194     ANGLEResources.MaxVertexTextureImageUnits = 0;
    195     getIntegerv(GraphicsContext3D::MAX_VERTEX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxVertexTextureImageUnits);
    196     ANGLEResources.MaxCombinedTextureImageUnits = 0;
    197     getIntegerv(GraphicsContext3D::MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxCombinedTextureImageUnits);
    198     ANGLEResources.MaxTextureImageUnits = 0;
    199     getIntegerv(GraphicsContext3D::MAX_TEXTURE_IMAGE_UNITS, &ANGLEResources.MaxTextureImageUnits);
    200     ANGLEResources.MaxFragmentUniformVectors = 0;
    201     getIntegerv(GraphicsContext3D::MAX_FRAGMENT_UNIFORM_VECTORS, &ANGLEResources.MaxFragmentUniformVectors);
    202 
    203     // Always set to 1 for OpenGL ES.
    204     ANGLEResources.MaxDrawBuffers = 1;
    205    
    206     m_compiler.setResources(ANGLEResources);
    207    
    208     ::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
    209     ::glClearColor(0, 0, 0, 0);
    210 }
    211 
    212 GraphicsContext3D::~GraphicsContext3D()
    213 {
    214     if (m_contextObj) {
    215         CGLSetCurrentContext(m_contextObj);
    216         ::glDeleteTextures(1, &m_texture);
    217         if (m_attrs.antialias) {
    218             ::glDeleteRenderbuffersEXT(1, &m_multisampleColorBuffer);
    219             if (m_attrs.stencil || m_attrs.depth)
    220                 ::glDeleteRenderbuffersEXT(1, &m_multisampleDepthStencilBuffer);
    221             ::glDeleteFramebuffersEXT(1, &m_multisampleFBO);
    222         } else {
    223             if (m_attrs.stencil || m_attrs.depth)
    224                 ::glDeleteRenderbuffersEXT(1, &m_depthStencilBuffer);
    225         }
    226         ::glDeleteFramebuffersEXT(1, &m_fbo);
    227         CGLSetCurrentContext(0);
    228         CGLDestroyContext(m_contextObj);
    229     }
    230 }
    23153
    23254void GraphicsContext3D::validateAttributes()
     
    25274    // correct behavior when premultipliedAlpha = false is requested.
    25375    m_attrs.premultipliedAlpha = true;
    254 }
    255 
    256 void GraphicsContext3D::makeContextCurrent()
    257 {
    258     CGLSetCurrentContext(m_contextObj);
    25976}
    26077
     
    305122    paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight,
    306123                  canvas->width(), canvas->height(), imageBuffer->context()->platformContext());
    307 }
    308 
    309 bool GraphicsContext3D::isGLES2Compliant() const
    310 {
    311     return false;
    312 }
    313 
    314 bool GraphicsContext3D::isGLES2NPOTStrict() const
    315 {
    316     return false;
    317 }
    318 
    319 bool GraphicsContext3D::isErrorGeneratedOnOutOfBoundsAccesses() const
    320 {
    321     return false;
    322124}
    323125
     
    453255}
    454256
    455 static inline void ensureContext(CGLContextObj context)
    456 {
    457     if (!context)
    458         return;
    459        
    460     CGLContextObj currentContext = CGLGetCurrentContext();
    461     if (currentContext != context)
    462         CGLSetCurrentContext(context);
    463 }
    464 
    465257void GraphicsContext3D::prepareTexture()
    466258{
    467     ensureContext(m_contextObj);
     259    ensureContext();
    468260    if (m_attrs.antialias) {
    469261        ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
     
    477269void GraphicsContext3D::activeTexture(unsigned long texture)
    478270{
    479     ensureContext(m_contextObj);
     271    ensureContext();
    480272    ::glActiveTexture(texture);
    481273}
     
    485277    ASSERT(program);
    486278    ASSERT(shader);
    487     ensureContext(m_contextObj);
     279    ensureContext();
    488280    ::glAttachShader((GLuint) program, (GLuint) shader);
    489281}
     
    492284{
    493285    ASSERT(program);
    494     ensureContext(m_contextObj);
     286    ensureContext();
    495287    ::glBindAttribLocation((GLuint) program, index, name.utf8().data());
    496288}
     
    498290void GraphicsContext3D::bindBuffer(unsigned long target, Platform3DObject buffer)
    499291{
    500     ensureContext(m_contextObj);
     292    ensureContext();
    501293    ::glBindBuffer(target, (GLuint) buffer);
    502294}
     
    505297void GraphicsContext3D::bindFramebuffer(unsigned long target, Platform3DObject buffer)
    506298{
    507     ensureContext(m_contextObj);
     299    ensureContext();
    508300    GLuint fbo;
    509301    if (buffer)
     
    519311void GraphicsContext3D::bindRenderbuffer(unsigned long target, Platform3DObject renderbuffer)
    520312{
    521     ensureContext(m_contextObj);
     313    ensureContext();
    522314    ::glBindRenderbufferEXT(target, (GLuint) renderbuffer);
    523315}
     
    526318void GraphicsContext3D::bindTexture(unsigned long target, Platform3DObject texture)
    527319{
    528     ensureContext(m_contextObj);
     320    ensureContext();
    529321    ::glBindTexture(target, (GLuint) texture);
    530322}
     
    532324void GraphicsContext3D::blendColor(double red, double green, double blue, double alpha)
    533325{
    534     ensureContext(m_contextObj);
     326    ensureContext();
    535327    ::glBlendColor(static_cast<float>(red), static_cast<float>(green), static_cast<float>(blue), static_cast<float>(alpha));
    536328}
    537329
    538 void GraphicsContext3D::blendEquation( unsigned long mode )
    539 {
    540     ensureContext(m_contextObj);
     330void GraphicsContext3D::blendEquation(unsigned long mode)
     331{
     332    ensureContext();
    541333    ::glBlendEquation(mode);
    542334}
     
    544336void GraphicsContext3D::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha)
    545337{
    546     ensureContext(m_contextObj);
     338    ensureContext();
    547339    ::glBlendEquationSeparate(modeRGB, modeAlpha);
    548340}
     
    551343void GraphicsContext3D::blendFunc(unsigned long sfactor, unsigned long dfactor)
    552344{
    553     ensureContext(m_contextObj);
     345    ensureContext();
    554346    ::glBlendFunc(sfactor, dfactor);
    555347}       
     
    557349void GraphicsContext3D::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha)
    558350{
    559     ensureContext(m_contextObj);
     351    ensureContext();
    560352    ::glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
    561353}
     
    563355void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long usage)
    564356{
    565     ensureContext(m_contextObj);
     357    ensureContext();
    566358    ::glBufferData(target, size, 0, usage);
    567359}
     
    569361void GraphicsContext3D::bufferData(unsigned long target, int size, const void* data, unsigned long usage)
    570362{
    571     ensureContext(m_contextObj);
     363    ensureContext();
    572364    ::glBufferData(target, size, data, usage);
    573365}
     
    575367void GraphicsContext3D::bufferSubData(unsigned long target, long offset, int size, const void* data)
    576368{
    577     ensureContext(m_contextObj);
     369    ensureContext();
    578370    ::glBufferSubData(target, offset, size, data);
    579371}
     
    581373unsigned long GraphicsContext3D::checkFramebufferStatus(unsigned long target)
    582374{
    583     ensureContext(m_contextObj);
     375    ensureContext();
    584376    return ::glCheckFramebufferStatusEXT(target);
    585377}
     
    587379void GraphicsContext3D::clearColor(double r, double g, double b, double a)
    588380{
    589     ensureContext(m_contextObj);
     381    ensureContext();
    590382    ::glClearColor(static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a));
    591383}
     
    593385void GraphicsContext3D::clear(unsigned long mask)
    594386{
    595     ensureContext(m_contextObj);
     387    ensureContext();
    596388    ::glClear(mask);
    597389}
     
    599391void GraphicsContext3D::clearDepth(double depth)
    600392{
    601     ensureContext(m_contextObj);
     393    ensureContext();
    602394    ::glClearDepth(depth);
    603395}
     
    605397void GraphicsContext3D::clearStencil(long s)
    606398{
    607     ensureContext(m_contextObj);
     399    ensureContext();
    608400    ::glClearStencil(s);
    609401}
     
    611403void GraphicsContext3D::colorMask(bool red, bool green, bool blue, bool alpha)
    612404{
    613     ensureContext(m_contextObj);
     405    ensureContext();
    614406    ::glColorMask(red, green, blue, alpha);
    615407}
     
    618410{
    619411    ASSERT(shader);
    620     ensureContext(m_contextObj);
     412    ensureContext();
    621413
    622414    int GLshaderType;
     
    669461void GraphicsContext3D::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border)
    670462{
    671     ensureContext(m_contextObj);
     463    ensureContext();
    672464    if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
    673465        ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
     
    683475void GraphicsContext3D::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height)
    684476{
    685     ensureContext(m_contextObj);
     477    ensureContext();
    686478    if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
    687479        ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
     
    697489void GraphicsContext3D::cullFace(unsigned long mode)
    698490{
    699     ensureContext(m_contextObj);
     491    ensureContext();
    700492    ::glCullFace(mode);
    701493}
     
    703495void GraphicsContext3D::depthFunc(unsigned long func)
    704496{
    705     ensureContext(m_contextObj);
     497    ensureContext();
    706498    ::glDepthFunc(func);
    707499}
     
    709501void GraphicsContext3D::depthMask(bool flag)
    710502{
    711     ensureContext(m_contextObj);
     503    ensureContext();
    712504    ::glDepthMask(flag);
    713505}
     
    715507void GraphicsContext3D::depthRange(double zNear, double zFar)
    716508{
    717     ensureContext(m_contextObj);
     509    ensureContext();
    718510    ::glDepthRange(zNear, zFar);
    719511}
     
    723515    ASSERT(program);
    724516    ASSERT(shader);
    725     ensureContext(m_contextObj);
     517    ensureContext();
    726518    ::glDetachShader((GLuint) program, (GLuint) shader);
    727519}
     
    729521void GraphicsContext3D::disable(unsigned long cap)
    730522{
    731     ensureContext(m_contextObj);
     523    ensureContext();
    732524    ::glDisable(cap);
    733525}
     
    735527void GraphicsContext3D::disableVertexAttribArray(unsigned long index)
    736528{
    737     ensureContext(m_contextObj);
     529    ensureContext();
    738530    ::glDisableVertexAttribArray(index);
    739531}
     
    741533void GraphicsContext3D::drawArrays(unsigned long mode, long first, long count)
    742534{
    743     ensureContext(m_contextObj);
     535    ensureContext();
    744536    ::glDrawArrays(mode, first, count);
    745537}
     
    747539void GraphicsContext3D::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset)
    748540{
    749     ensureContext(m_contextObj);
     541    ensureContext();
    750542    ::glDrawElements(mode, count, type, reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
    751543}
     
    753545void GraphicsContext3D::enable(unsigned long cap)
    754546{
    755     ensureContext(m_contextObj);
     547    ensureContext();
    756548    ::glEnable(cap);
    757549}
     
    759551void GraphicsContext3D::enableVertexAttribArray(unsigned long index)
    760552{
    761     ensureContext(m_contextObj);
     553    ensureContext();
    762554    ::glEnableVertexAttribArray(index);
    763555}
     
    765557void GraphicsContext3D::finish()
    766558{
    767     ensureContext(m_contextObj);
     559    ensureContext();
    768560    ::glFinish();
    769561}
     
    771563void GraphicsContext3D::flush()
    772564{
    773     ensureContext(m_contextObj);
     565    ensureContext();
    774566    ::glFlush();
    775567}
     
    777569void GraphicsContext3D::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, Platform3DObject buffer)
    778570{
    779     ensureContext(m_contextObj);
     571    ensureContext();
    780572    GLuint renderbuffer = (GLuint) buffer;
    781573    if (attachment == DEPTH_STENCIL_ATTACHMENT) {
     
    788580void GraphicsContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, Platform3DObject texture, long level)
    789581{
    790     ensureContext(m_contextObj);
     582    ensureContext();
    791583    ::glFramebufferTexture2DEXT(target, attachment, textarget, (GLuint) texture, level);
    792584}
     
    794586void GraphicsContext3D::frontFace(unsigned long mode)
    795587{
    796     ensureContext(m_contextObj);
     588    ensureContext();
    797589    ::glFrontFace(mode);
    798590}
     
    800592void GraphicsContext3D::generateMipmap(unsigned long target)
    801593{
    802     ensureContext(m_contextObj);
     594    ensureContext();
    803595    ::glGenerateMipmapEXT(target);
    804596}
     
    810602        return false;
    811603    }
    812     ensureContext(m_contextObj);
     604    ensureContext();
    813605    GLint maxAttributeSize = 0;
    814606    ::glGetProgramiv(static_cast<GLuint>(program), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeSize);
     
    832624        return false;
    833625    }
    834     ensureContext(m_contextObj);
     626    ensureContext();
    835627    GLint maxUniformSize = 0;
    836628    ::glGetProgramiv(static_cast<GLuint>(program), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformSize);
     
    854646        return;
    855647    }
    856     ensureContext(m_contextObj);
     648    ensureContext();
    857649    ::glGetAttachedShaders(static_cast<GLuint>(program), maxCount, count, shaders);
    858650}
     
    862654    if (!program)
    863655        return -1;
    864    
    865     ensureContext(m_contextObj);
     656
     657    ensureContext();
    866658    return ::glGetAttribLocation((GLuint) program, name.utf8().data());
    867659}
     
    881673    }
    882674
    883     ensureContext(m_contextObj);
     675    ensureContext();
    884676    return ::glGetError();
    885677}
     
    887679String GraphicsContext3D::getString(unsigned long name)
    888680{
    889     ensureContext(m_contextObj);
     681    ensureContext();
    890682    return String((const char*) ::glGetString(name));
    891683}
     
    893685void GraphicsContext3D::hint(unsigned long target, unsigned long mode)
    894686{
    895     ensureContext(m_contextObj);
     687    ensureContext();
    896688    ::glHint(target, mode);
    897689}
     
    901693    if (!buffer)
    902694        return false;
    903    
    904     ensureContext(m_contextObj);
     695
     696    ensureContext();
    905697    return ::glIsBuffer((GLuint) buffer);
    906698}
     
    908700bool GraphicsContext3D::isEnabled(unsigned long cap)
    909701{
    910     ensureContext(m_contextObj);
     702    ensureContext();
    911703    return ::glIsEnabled(cap);
    912704}
     
    916708    if (!framebuffer)
    917709        return false;
    918    
    919     ensureContext(m_contextObj);
     710
     711    ensureContext();
    920712    return ::glIsFramebufferEXT((GLuint) framebuffer);
    921713}
     
    925717    if (!program)
    926718        return false;
    927    
    928     ensureContext(m_contextObj);
     719
     720    ensureContext();
    929721    return ::glIsProgram((GLuint) program);
    930722}
     
    934726    if (!renderbuffer)
    935727        return false;
    936    
    937     ensureContext(m_contextObj);
     728
     729    ensureContext();
    938730    return ::glIsRenderbufferEXT((GLuint) renderbuffer);
    939731}
     
    943735    if (!shader)
    944736        return false;
    945    
    946     ensureContext(m_contextObj);
     737
     738    ensureContext();
    947739    return ::glIsShader((GLuint) shader);
    948740}
     
    952744    if (!texture)
    953745        return false;
    954    
    955     ensureContext(m_contextObj);
     746
     747    ensureContext();
    956748    return ::glIsTexture((GLuint) texture);
    957749}
     
    959751void GraphicsContext3D::lineWidth(double width)
    960752{
    961     ensureContext(m_contextObj);
     753    ensureContext();
    962754    ::glLineWidth(static_cast<float>(width));
    963755}
     
    966758{
    967759    ASSERT(program);
    968     ensureContext(m_contextObj);
     760    ensureContext();
    969761    ::glLinkProgram((GLuint) program);
    970762}
     
    972764void GraphicsContext3D::pixelStorei(unsigned long pname, long param)
    973765{
    974     ensureContext(m_contextObj);
     766    ensureContext();
    975767    ::glPixelStorei(pname, param);
    976768}
     
    978770void GraphicsContext3D::polygonOffset(double factor, double units)
    979771{
    980     ensureContext(m_contextObj);
     772    ensureContext();
    981773    ::glPolygonOffset(static_cast<float>(factor), static_cast<float>(units));
    982774}
     
    986778    // FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
    987779    // all previous rendering calls should be done before reading pixels.
    988     ensureContext(m_contextObj);
     780    ensureContext();
    989781    ::glFlush();
    990782    if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
     
    1003795{
    1004796    // FIXME: This is not implemented on desktop OpenGL. We need to have ifdefs for the different GL variants
    1005     ensureContext(m_contextObj);
    1006     //::glReleaseShaderCompiler();
    1007797}
    1008798
    1009799void GraphicsContext3D::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height)
    1010800{
    1011     ensureContext(m_contextObj);
     801    ensureContext();
    1012802    switch (internalformat) {
    1013803    case DEPTH_STENCIL:
     
    1030820void GraphicsContext3D::sampleCoverage(double value, bool invert)
    1031821{
    1032     ensureContext(m_contextObj);
     822    ensureContext();
    1033823    ::glSampleCoverage(static_cast<float>(value), invert);
    1034824}
     
    1036826void GraphicsContext3D::scissor(long x, long y, unsigned long width, unsigned long height)
    1037827{
    1038     ensureContext(m_contextObj);
     828    ensureContext();
    1039829    ::glScissor(x, y, width, height);
    1040830}
     
    1043833{
    1044834    ASSERT(shader);
    1045    
    1046     ensureContext(m_contextObj);
     835
     836    ensureContext();
    1047837
    1048838    ShaderSourceEntry entry;
     
    1055845void GraphicsContext3D::stencilFunc(unsigned long func, long ref, unsigned long mask)
    1056846{
    1057     ensureContext(m_contextObj);
     847    ensureContext();
    1058848    ::glStencilFunc(func, ref, mask);
    1059849}
     
    1061851void GraphicsContext3D::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask)
    1062852{
    1063     ensureContext(m_contextObj);
     853    ensureContext();
    1064854    ::glStencilFuncSeparate(face, func, ref, mask);
    1065855}
     
    1067857void GraphicsContext3D::stencilMask(unsigned long mask)
    1068858{
    1069     ensureContext(m_contextObj);
     859    ensureContext();
    1070860    ::glStencilMask(mask);
    1071861}
     
    1073863void GraphicsContext3D::stencilMaskSeparate(unsigned long face, unsigned long mask)
    1074864{
    1075     ensureContext(m_contextObj);
     865    ensureContext();
    1076866    ::glStencilMaskSeparate(face, mask);
    1077867}
     
    1079869void GraphicsContext3D::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass)
    1080870{
    1081     ensureContext(m_contextObj);
     871    ensureContext();
    1082872    ::glStencilOp(fail, zfail, zpass);
    1083873}
     
    1085875void GraphicsContext3D::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass)
    1086876{
    1087     ensureContext(m_contextObj);
     877    ensureContext();
    1088878    ::glStencilOpSeparate(face, fail, zfail, zpass);
    1089879}
     
    1091881void GraphicsContext3D::texParameterf(unsigned target, unsigned pname, float value)
    1092882{
    1093     ensureContext(m_contextObj);
     883    ensureContext();
    1094884    ::glTexParameterf(target, pname, static_cast<float>(value));
    1095885}
     
    1097887void GraphicsContext3D::texParameteri(unsigned target, unsigned pname, int value)
    1098888{
    1099     ensureContext(m_contextObj);
     889    ensureContext();
    1100890    ::glTexParameteri(target, pname, static_cast<float>(value));
    1101891}
     
    1103893void GraphicsContext3D::uniform1f(long location, float v0)
    1104894{
    1105     ensureContext(m_contextObj);
     895    ensureContext();
    1106896    ::glUniform1f(location, v0);
    1107897}
     
    1109899void GraphicsContext3D::uniform1fv(long location, float* array, int size)
    1110900{
    1111     ensureContext(m_contextObj);
     901    ensureContext();
    1112902    ::glUniform1fv(location, size, array);
    1113903}
     
    1115905void GraphicsContext3D::uniform2f(long location, float v0, float v1)
    1116906{
    1117     ensureContext(m_contextObj);
     907    ensureContext();
    1118908    ::glUniform2f(location, v0, v1);
    1119909}
     
    1122912{
    1123913    // FIXME: length needs to be a multiple of 2
    1124     ensureContext(m_contextObj);
     914    ensureContext();
    1125915    ::glUniform2fv(location, size, array);
    1126916}
     
    1128918void GraphicsContext3D::uniform3f(long location, float v0, float v1, float v2)
    1129919{
    1130     ensureContext(m_contextObj);
     920    ensureContext();
    1131921    ::glUniform3f(location, v0, v1, v2);
    1132922}
     
    1135925{
    1136926    // FIXME: length needs to be a multiple of 3
    1137     ensureContext(m_contextObj);
     927    ensureContext();
    1138928    ::glUniform3fv(location, size, array);
    1139929}
     
    1141931void GraphicsContext3D::uniform4f(long location, float v0, float v1, float v2, float v3)
    1142932{
    1143     ensureContext(m_contextObj);
     933    ensureContext();
    1144934    ::glUniform4f(location, v0, v1, v2, v3);
    1145935}
     
    1148938{
    1149939    // FIXME: length needs to be a multiple of 4
    1150     ensureContext(m_contextObj);
     940    ensureContext();
    1151941    ::glUniform4fv(location, size, array);
    1152942}
     
    1154944void GraphicsContext3D::uniform1i(long location, int v0)
    1155945{
    1156     ensureContext(m_contextObj);
     946    ensureContext();
    1157947    ::glUniform1i(location, v0);
    1158948}
     
    1160950void GraphicsContext3D::uniform1iv(long location, int* array, int size)
    1161951{
    1162     ensureContext(m_contextObj);
     952    ensureContext();
    1163953    ::glUniform1iv(location, size, array);
    1164954}
     
    1166956void GraphicsContext3D::uniform2i(long location, int v0, int v1)
    1167957{
    1168     ensureContext(m_contextObj);
     958    ensureContext();
    1169959    ::glUniform2i(location, v0, v1);
    1170960}
     
    1173963{
    1174964    // FIXME: length needs to be a multiple of 2
    1175     ensureContext(m_contextObj);
     965    ensureContext();
    1176966    ::glUniform2iv(location, size, array);
    1177967}
     
    1179969void GraphicsContext3D::uniform3i(long location, int v0, int v1, int v2)
    1180970{
    1181     ensureContext(m_contextObj);
     971    ensureContext();
    1182972    ::glUniform3i(location, v0, v1, v2);
    1183973}
     
    1186976{
    1187977    // FIXME: length needs to be a multiple of 3
    1188     ensureContext(m_contextObj);
     978    ensureContext();
    1189979    ::glUniform3iv(location, size, array);
    1190980}
     
    1192982void GraphicsContext3D::uniform4i(long location, int v0, int v1, int v2, int v3)
    1193983{
    1194     ensureContext(m_contextObj);
     984    ensureContext();
    1195985    ::glUniform4i(location, v0, v1, v2, v3);
    1196986}
     
    1199989{
    1200990    // FIXME: length needs to be a multiple of 4
    1201     ensureContext(m_contextObj);
     991    ensureContext();
    1202992    ::glUniform4iv(location, size, array);
    1203993}
     
    1206996{
    1207997    // FIXME: length needs to be a multiple of 4
    1208     ensureContext(m_contextObj);
     998    ensureContext();
    1209999    ::glUniformMatrix2fv(location, size, transpose, array);
    12101000}
     
    12131003{
    12141004    // FIXME: length needs to be a multiple of 9
    1215     ensureContext(m_contextObj);
     1005    ensureContext();
    12161006    ::glUniformMatrix3fv(location, size, transpose, array);
    12171007}
     
    12201010{
    12211011    // FIXME: length needs to be a multiple of 16
    1222     ensureContext(m_contextObj);
     1012    ensureContext();
    12231013    ::glUniformMatrix4fv(location, size, transpose, array);
    12241014}
     
    12261016void GraphicsContext3D::useProgram(Platform3DObject program)
    12271017{
    1228     ensureContext(m_contextObj);
     1018    ensureContext();
    12291019    ::glUseProgram((GLuint) program);
    12301020}
     
    12331023{
    12341024    ASSERT(program);
    1235    
    1236     ensureContext(m_contextObj);
     1025
     1026    ensureContext();
    12371027    ::glValidateProgram((GLuint) program);
    12381028}
     
    12401030void GraphicsContext3D::vertexAttrib1f(unsigned long indx, float v0)
    12411031{
    1242     ensureContext(m_contextObj);
     1032    ensureContext();
    12431033    ::glVertexAttrib1f(indx, v0);
    12441034}
     
    12461036void GraphicsContext3D::vertexAttrib1fv(unsigned long indx, float* array)
    12471037{
    1248     ensureContext(m_contextObj);
     1038    ensureContext();
    12491039    ::glVertexAttrib1fv(indx, array);
    12501040}
     
    12521042void GraphicsContext3D::vertexAttrib2f(unsigned long indx, float v0, float v1)
    12531043{
    1254     ensureContext(m_contextObj);
     1044    ensureContext();
    12551045    ::glVertexAttrib2f(indx, v0, v1);
    12561046}
     
    12581048void GraphicsContext3D::vertexAttrib2fv(unsigned long indx, float* array)
    12591049{
    1260     ensureContext(m_contextObj);
     1050    ensureContext();
    12611051    ::glVertexAttrib2fv(indx, array);
    12621052}
     
    12641054void GraphicsContext3D::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2)
    12651055{
    1266     ensureContext(m_contextObj);
     1056    ensureContext();
    12671057    ::glVertexAttrib3f(indx, v0, v1, v2);
    12681058}
     
    12701060void GraphicsContext3D::vertexAttrib3fv(unsigned long indx, float* array)
    12711061{
    1272     ensureContext(m_contextObj);
     1062    ensureContext();
    12731063    ::glVertexAttrib3fv(indx, array);
    12741064}
     
    12761066void GraphicsContext3D::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3)
    12771067{
    1278     ensureContext(m_contextObj);
     1068    ensureContext();
    12791069    ::glVertexAttrib4f(indx, v0, v1, v2, v3);
    12801070}
     
    12821072void GraphicsContext3D::vertexAttrib4fv(unsigned long indx, float* array)
    12831073{
    1284     ensureContext(m_contextObj);
     1074    ensureContext();
    12851075    ::glVertexAttrib4fv(indx, array);
    12861076}
     
    12881078void GraphicsContext3D::vertexAttribPointer(unsigned long indx, int size, int type, bool normalized, unsigned long stride, unsigned long offset)
    12891079{
    1290     ensureContext(m_contextObj);
     1080    ensureContext();
    12911081    ::glVertexAttribPointer(indx, size, type, normalized, stride, reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
    12921082}
     
    12941084void GraphicsContext3D::viewport(long x, long y, unsigned long width, unsigned long height)
    12951085{
    1296     ensureContext(m_contextObj);
     1086    ensureContext();
    12971087    ::glViewport(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
    12981088}
     
    13001090void GraphicsContext3D::getBooleanv(unsigned long pname, unsigned char* value)
    13011091{
    1302     ensureContext(m_contextObj);
     1092    ensureContext();
    13031093    ::glGetBooleanv(pname, value);
    13041094}
     
    13061096void GraphicsContext3D::getBufferParameteriv(unsigned long target, unsigned long pname, int* value)
    13071097{
    1308     ensureContext(m_contextObj);
     1098    ensureContext();
    13091099    ::glGetBufferParameteriv(target, pname, value);
    13101100}
     
    13121102void GraphicsContext3D::getFloatv(unsigned long pname, float* value)
    13131103{
    1314     ensureContext(m_contextObj);
     1104    ensureContext();
    13151105    ::glGetFloatv(pname, value);
    13161106}
     
    13181108void GraphicsContext3D::getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname, int* value)
    13191109{
    1320     ensureContext(m_contextObj);
     1110    ensureContext();
    13211111    if (attachment == DEPTH_STENCIL_ATTACHMENT)
    13221112        attachment = DEPTH_ATTACHMENT; // Or STENCIL_ATTACHMENT, either works.
     
    13331123    // whereas GLES2 return the number of vectors (each vector has 4 components).
    13341124    // Therefore, the value returned by desktop GL needs to be divided by 4.
    1335     ensureContext(m_contextObj);
     1125    ensureContext();
    13361126    switch (pname) {
    13371127    case IMPLEMENTATION_COLOR_READ_FORMAT:
     
    13601150void GraphicsContext3D::getProgramiv(Platform3DObject program, unsigned long pname, int* value)
    13611151{
    1362     ensureContext(m_contextObj);
     1152    ensureContext();
    13631153    ::glGetProgramiv((GLuint) program, pname, value);
    13641154}
     
    13671157{
    13681158    ASSERT(program);
    1369    
    1370     ensureContext(m_contextObj);
     1159
     1160    ensureContext();
    13711161    GLint length;
    13721162    ::glGetProgramiv((GLuint) program, GL_INFO_LOG_LENGTH, &length);
     
    13851175void GraphicsContext3D::getRenderbufferParameteriv(unsigned long target, unsigned long pname, int* value)
    13861176{
    1387     ensureContext(m_contextObj);
     1177    ensureContext();
    13881178    ::glGetRenderbufferParameterivEXT(target, pname, value);
    13891179}
     
    13921182{
    13931183    ASSERT(shader);
    1394    
    1395     ensureContext(m_contextObj);
    1396    
     1184
     1185    ensureContext();
     1186
    13971187    HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader);
    13981188   
    13991189    switch (pname) {
    1400         case DELETE_STATUS:
    1401         case SHADER_TYPE:
    1402             // Let OpenGL handle these.
    1403        
    1404             ::glGetShaderiv((GLuint) shader, pname, value);
    1405             break;
    1406 
    1407         case COMPILE_STATUS:
    1408             if (result == m_shaderSourceMap.end()) {
    1409                 (*value) = static_cast<int>(false);
    1410                 return;
    1411             }
    1412                
    1413             (*value) = static_cast<int>(result->second.isValid);
    1414             break;
    1415            
    1416         case INFO_LOG_LENGTH:
    1417             if (result == m_shaderSourceMap.end()) {
    1418                 (*value) = 0;
    1419                 return;
    1420             }
    1421            
    1422             (*value) = getShaderInfoLog(shader).length();
    1423             break;
    1424            
    1425         case SHADER_SOURCE_LENGTH:
    1426             (*value) = getShaderSource(shader).length();
    1427             break;
    1428        
    1429         default:
    1430             synthesizeGLError(INVALID_ENUM);
     1190    case DELETE_STATUS:
     1191    case SHADER_TYPE:
     1192        // Let OpenGL handle these.
     1193   
     1194        ::glGetShaderiv((GLuint) shader, pname, value);
     1195        break;
     1196   
     1197    case COMPILE_STATUS:
     1198        if (result == m_shaderSourceMap.end()) {
     1199            (*value) = static_cast<int>(false);
     1200            return;
     1201        }
     1202   
     1203        (*value) = static_cast<int>(result->second.isValid);
     1204        break;
     1205   
     1206    case INFO_LOG_LENGTH:
     1207        if (result == m_shaderSourceMap.end()) {
     1208            (*value) = 0;
     1209            return;
     1210        }
     1211   
     1212        (*value) = getShaderInfoLog(shader).length();
     1213        break;
     1214   
     1215    case SHADER_SOURCE_LENGTH:
     1216        (*value) = getShaderSource(shader).length();
     1217        break;
     1218   
     1219    default:
     1220        synthesizeGLError(INVALID_ENUM);
    14311221    }
    14321222}
     
    14361226    ASSERT(shader);
    14371227
    1438     ensureContext(m_contextObj);
     1228    ensureContext();
    14391229    GLint length;
    14401230    ::glGetShaderiv((GLuint) shader, GL_INFO_LOG_LENGTH, &length);
     
    14481238
    14491239     if (entry.isValid) {
    1450          GLint length;
    1451          ::glGetShaderiv((GLuint) shader, GL_INFO_LOG_LENGTH, &length);
    1452 
    1453          GLsizei size;
    1454          GLchar* info = (GLchar*) fastMalloc(length);
    1455          if (!info)
    1456              return "";
    1457 
    1458          ::glGetShaderInfoLog((GLuint) shader, length, &size, info);
    1459 
    1460          String s(info);
    1461          fastFree(info);
    1462          return s;
    1463      }
    1464      else {
    1465          return entry.log;
    1466      }
     1240        GLint length;
     1241        ::glGetShaderiv((GLuint) shader, GL_INFO_LOG_LENGTH, &length);
     1242
     1243        GLsizei size;
     1244        GLchar* info = (GLchar*) fastMalloc(length);
     1245        if (!info)
     1246            return "";
     1247
     1248        ::glGetShaderInfoLog((GLuint) shader, length, &size, info);
     1249
     1250        String s(info);
     1251        fastFree(info);
     1252        return s;
     1253    }
     1254   
     1255    return entry.log;
    14671256}
    14681257
     
    14711260    ASSERT(shader);
    14721261
    1473     ensureContext(m_contextObj);
     1262    ensureContext();
    14741263
    14751264    HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader);
     
    14841273void GraphicsContext3D::getTexParameterfv(unsigned long target, unsigned long pname, float* value)
    14851274{
    1486     ensureContext(m_contextObj);
     1275    ensureContext();
    14871276    ::glGetTexParameterfv(target, pname, value);
    14881277}
     
    14901279void GraphicsContext3D::getTexParameteriv(unsigned long target, unsigned long pname, int* value)
    14911280{
    1492     ensureContext(m_contextObj);
     1281    ensureContext();
    14931282    ::glGetTexParameteriv(target, pname, value);
    14941283}
     
    14961285void GraphicsContext3D::getUniformfv(Platform3DObject program, long location, float* value)
    14971286{
    1498     ensureContext(m_contextObj);
     1287    ensureContext();
    14991288    ::glGetUniformfv((GLuint) program, location, value);
    15001289}
     
    15021291void GraphicsContext3D::getUniformiv(Platform3DObject program, long location, int* value)
    15031292{
    1504     ensureContext(m_contextObj);
     1293    ensureContext();
    15051294    ::glGetUniformiv((GLuint) program, location, value);
    15061295}
     
    15091298{
    15101299    ASSERT(program);
    1511    
    1512     ensureContext(m_contextObj);
     1300
     1301    ensureContext();
    15131302    return ::glGetUniformLocation((GLuint) program, name.utf8().data());
    15141303}
     
    15161305void GraphicsContext3D::getVertexAttribfv(unsigned long index, unsigned long pname, float* value)
    15171306{
    1518     ensureContext(m_contextObj);
     1307    ensureContext();
    15191308    ::glGetVertexAttribfv(index, pname, value);
    15201309}
     
    15221311void GraphicsContext3D::getVertexAttribiv(unsigned long index, unsigned long pname, int* value)
    15231312{
    1524     ensureContext(m_contextObj);
     1313    ensureContext();
    15251314    ::glGetVertexAttribiv(index, pname, value);
    15261315}
     
    15281317long GraphicsContext3D::getVertexAttribOffset(unsigned long index, unsigned long pname)
    15291318{
    1530     ensureContext(m_contextObj);
    1531    
     1319    ensureContext();
     1320
    15321321    void* pointer;
    15331322    ::glGetVertexAttribPointerv(index, pname, &pointer);
     
    15371326int GraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels)
    15381327{
    1539     ensureContext(m_contextObj);
     1328    ensureContext();
    15401329
    15411330    ::glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
     
    15451334int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels)
    15461335{
    1547     ensureContext(m_contextObj);
     1336    ensureContext();
    15481337
    15491338    // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size
     
    15541343unsigned GraphicsContext3D::createBuffer()
    15551344{
    1556     ensureContext(m_contextObj);
     1345    ensureContext();
    15571346    GLuint o;
    15581347    glGenBuffers(1, &o);
     
    15621351unsigned GraphicsContext3D::createFramebuffer()
    15631352{
    1564     ensureContext(m_contextObj);
     1353    ensureContext();
    15651354    GLuint o;
    15661355    glGenFramebuffersEXT(1, &o);
     
    15701359unsigned GraphicsContext3D::createProgram()
    15711360{
    1572     ensureContext(m_contextObj);
     1361    ensureContext();
    15731362    return glCreateProgram();
    15741363}
     
    15761365unsigned GraphicsContext3D::createRenderbuffer()
    15771366{
    1578     ensureContext(m_contextObj);
     1367    ensureContext();
    15791368    GLuint o;
    15801369    glGenRenderbuffersEXT(1, &o);
     
    15841373unsigned GraphicsContext3D::createShader(unsigned long type)
    15851374{
    1586     ensureContext(m_contextObj);
     1375    ensureContext();
    15871376    return glCreateShader((type == FRAGMENT_SHADER) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER);
    15881377}
     
    15901379unsigned GraphicsContext3D::createTexture()
    15911380{
    1592     ensureContext(m_contextObj);
     1381    ensureContext();
    15931382    GLuint o;
    15941383    glGenTextures(1, &o);
     
    15981387void GraphicsContext3D::deleteBuffer(unsigned buffer)
    15991388{
    1600     ensureContext(m_contextObj);
     1389    ensureContext();
    16011390    glDeleteBuffers(1, &buffer);
    16021391}
     
    16041393void GraphicsContext3D::deleteFramebuffer(unsigned framebuffer)
    16051394{
    1606     ensureContext(m_contextObj);
     1395    ensureContext();
    16071396    glDeleteFramebuffersEXT(1, &framebuffer);
    16081397}
     
    16101399void GraphicsContext3D::deleteProgram(unsigned program)
    16111400{
    1612     ensureContext(m_contextObj);
     1401    ensureContext();
    16131402    glDeleteProgram(program);
    16141403}
     
    16161405void GraphicsContext3D::deleteRenderbuffer(unsigned renderbuffer)
    16171406{
    1618     ensureContext(m_contextObj);
     1407    ensureContext();
    16191408    glDeleteRenderbuffersEXT(1, &renderbuffer);
    16201409}
     
    16221411void GraphicsContext3D::deleteShader(unsigned shader)
    16231412{
    1624     ensureContext(m_contextObj);
     1413    ensureContext();
    16251414    glDeleteShader(shader);
    16261415}
     
    16281417void GraphicsContext3D::deleteTexture(unsigned texture)
    16291418{
    1630     ensureContext(m_contextObj);
     1419    ensureContext();
    16311420    glDeleteTextures(1, &texture);
    16321421}
     
    16351424{
    16361425    switch (type) {
    1637         case GL_BYTE:
    1638             return sizeof(GLbyte);
    1639         case GL_UNSIGNED_BYTE:
    1640             return sizeof(GLubyte);
    1641         case GL_SHORT:
    1642             return sizeof(GLshort);
    1643         case GL_UNSIGNED_SHORT:
    1644             return sizeof(GLushort);
    1645         case GL_INT:
    1646             return sizeof(GLint);
    1647         case GL_UNSIGNED_INT:
    1648             return sizeof(GLuint);
    1649         case GL_FLOAT:
    1650             return sizeof(GLfloat);
    1651         default:
    1652             return 0;
     1426    case GL_BYTE:
     1427        return sizeof(GLbyte);
     1428    case GL_UNSIGNED_BYTE:
     1429        return sizeof(GLubyte);
     1430    case GL_SHORT:
     1431        return sizeof(GLshort);
     1432    case GL_UNSIGNED_SHORT:
     1433        return sizeof(GLushort);
     1434    case GL_INT:
     1435        return sizeof(GLint);
     1436    case GL_UNSIGNED_INT:
     1437        return sizeof(GLuint);
     1438    case GL_FLOAT:
     1439        return sizeof(GLfloat);
     1440    default:
     1441        return 0;
    16531442    }
    16541443}
  • trunk/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm

    r66675 r66781  
    3232#import "BlockExceptions.h"
    3333
     34#include "ANGLE/ShaderLang.h"
    3435#include "ArrayBuffer.h"
    3536#include "ArrayBufferView.h"
    36 #include "WebGLObject.h"
    3737#include "CanvasRenderingContext.h"
     38#include <CoreGraphics/CGBitmapContext.h>
    3839#include "Float32Array.h"
    3940#include "GraphicsContext.h"
     
    4243#include "Int32Array.h"
    4344#include "NotImplemented.h"
     45#include <OpenGL/CGLRenderers.h>
     46#include <OpenGL/gl.h>
    4447#include "Uint8Array.h"
    4548#include "WebGLLayer.h"
    46 #include <CoreGraphics/CGBitmapContext.h>
    47 #include <OpenGL/CGLRenderers.h>
    48 #include <OpenGL/gl.h>
     49#include "WebGLObject.h"
    4950#include <wtf/UnusedParam.h>
    5051#include <wtf/text/CString.h>
     
    230231}
    231232
    232 void GraphicsContext3D::validateAttributes()
    233 {
    234     const char* extensions = reinterpret_cast<const char*>(::glGetString(GL_EXTENSIONS));
    235     if (m_attrs.stencil) {
    236         if (std::strstr(extensions, "GL_EXT_packed_depth_stencil")) {
    237             if (!m_attrs.depth)
    238                 m_attrs.depth = true;
    239         } else
    240             m_attrs.stencil = false;
    241     }
    242     if (m_attrs.antialias) {
    243         bool isValidVendor = true;
    244         // Currently in Mac we only turn on antialias if vendor is NVIDIA.
    245         const char* vendor = reinterpret_cast<const char*>(::glGetString(GL_VENDOR));
    246         if (!std::strstr(vendor, "NVIDIA"))
    247             isValidVendor = false;
    248         if (!isValidVendor || !std::strstr(extensions, "GL_EXT_framebuffer_multisample"))
    249             m_attrs.antialias = false;
    250     }
    251     // FIXME: instead of enforcing premultipliedAlpha = true, implement the
    252     // correct behavior when premultipliedAlpha = false is requested.
    253     m_attrs.premultipliedAlpha = true;
    254 }
    255 
    256 void GraphicsContext3D::makeContextCurrent()
    257 {
    258     CGLSetCurrentContext(m_contextObj);
    259 }
    260 
    261 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context)
    262 {
    263     HTMLCanvasElement* canvas = context->canvas();
    264     ImageBuffer* imageBuffer = canvas->buffer();
    265 
    266     int rowBytes = m_currentWidth * 4;
    267     int totalBytes = rowBytes * m_currentHeight;
    268 
    269     OwnArrayPtr<unsigned char> pixels(new unsigned char[totalBytes]);
    270     if (!pixels)
     233void GraphicsContext3D::ensureContext()
     234{
     235    if (!m_contextObj)
    271236        return;
    272237
    273     CGLSetCurrentContext(m_contextObj);
    274 
    275     bool mustRestoreFBO = false;
    276     if (m_attrs.antialias) {
    277         ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
    278         ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
    279         ::glBlitFramebufferEXT(0, 0, m_currentWidth, m_currentHeight, 0, 0, m_currentWidth, m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
    280         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    281         mustRestoreFBO = true;
    282     } else {
    283         if (m_boundFBO != m_fbo) {
    284             mustRestoreFBO = true;
    285             ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    286         }
    287     }
    288 
    289     GLint packAlignment = 4;
    290     bool mustRestorePackAlignment = false;
    291     ::glGetIntegerv(GL_PACK_ALIGNMENT, &packAlignment);
    292     if (packAlignment > 4) {
    293         ::glPixelStorei(GL_PACK_ALIGNMENT, 4);
    294         mustRestorePackAlignment = true;
    295     }
    296 
    297     ::glReadPixels(0, 0, m_currentWidth, m_currentHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels.get());
    298 
    299     if (mustRestorePackAlignment)
    300         ::glPixelStorei(GL_PACK_ALIGNMENT, packAlignment);
    301 
    302     if (mustRestoreFBO)
    303         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
    304 
    305     paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight,
    306                   canvas->width(), canvas->height(), imageBuffer->context()->platformContext());
     238    CGLContextObj currentContext = CGLGetCurrentContext();
     239    if (currentContext != m_contextObj)
     240        CGLSetCurrentContext(m_contextObj);
    307241}
    308242
     
    321255    return false;
    322256}
    323 
    324 void GraphicsContext3D::reshape(int width, int height)
    325 {
    326     if (width == m_currentWidth && height == m_currentHeight || !m_contextObj)
    327         return;
    328    
    329     m_currentWidth = width;
    330     m_currentHeight = height;
    331    
    332     CGLSetCurrentContext(m_contextObj);
    333    
    334     GLuint internalColorFormat, colorFormat, internalDepthStencilFormat = 0;
    335     if (m_attrs.alpha) {
    336         internalColorFormat = GL_RGBA8;
    337         colorFormat = GL_RGBA;
    338     } else {
    339         internalColorFormat = GL_RGB8;
    340         colorFormat = GL_RGB;
    341     }
    342     if (m_attrs.stencil || m_attrs.depth) {
    343         // We don't allow the logic where stencil is required and depth is not.
    344         // See GraphicsContext3D constructor.
    345         if (m_attrs.stencil && m_attrs.depth)
    346             internalDepthStencilFormat = GL_DEPTH24_STENCIL8_EXT;
    347         else
    348             internalDepthStencilFormat = GL_DEPTH_COMPONENT;
    349     }
    350 
    351     bool mustRestoreFBO = false;
    352 
    353     // resize multisample FBO
    354     if (m_attrs.antialias) {
    355         GLint maxSampleCount;
    356         ::glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSampleCount);
    357         GLint sampleCount = std::min(8, maxSampleCount);
    358         if (sampleCount > maxSampleCount)
    359             sampleCount = maxSampleCount;
    360         if (m_boundFBO != m_multisampleFBO) {
    361             ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
    362             mustRestoreFBO = true;
    363         }
    364         ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_multisampleColorBuffer);
    365         ::glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, sampleCount, internalColorFormat, width, height);
    366         ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, m_multisampleColorBuffer);
    367         if (m_attrs.stencil || m_attrs.depth) {
    368             ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer);
    369             ::glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, sampleCount, internalDepthStencilFormat, width, height);
    370             if (m_attrs.stencil)
    371                 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer);
    372             if (m_attrs.depth)
    373                 ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_multisampleDepthStencilBuffer);
    374         }
    375         ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    376         if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
    377             // FIXME: cleanup.
    378             notImplemented();
    379         }
    380     }
    381 
    382     // resize regular FBO
    383     if (m_boundFBO != m_fbo) {
    384         mustRestoreFBO = true;
    385         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    386     }
    387     ::glBindTexture(GL_TEXTURE_2D, m_texture);
    388     ::glTexImage2D(GL_TEXTURE_2D, 0, internalColorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
    389     ::glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_texture, 0);
    390     ::glBindTexture(GL_TEXTURE_2D, 0);
    391     if (!m_attrs.antialias && (m_attrs.stencil || m_attrs.depth)) {
    392         ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
    393         ::glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, internalDepthStencilFormat, width, height);
    394         if (m_attrs.stencil)
    395             ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
    396         if (m_attrs.depth)
    397             ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, m_depthStencilBuffer);
    398         ::glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);
    399     }
    400     if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) {
    401         // FIXME: cleanup
    402         notImplemented();
    403     }
    404 
    405     if (m_attrs.antialias) {
    406         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
    407         if (m_boundFBO == m_multisampleFBO)
    408             mustRestoreFBO = false;
    409     }
    410 
    411     // Initialize renderbuffers to 0.
    412     GLboolean colorMask[] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}, depthMask = GL_TRUE, stencilMask = GL_TRUE;
    413     GLboolean isScissorEnabled = GL_FALSE;
    414     GLboolean isDitherEnabled = GL_FALSE;
    415     GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
    416     ::glGetBooleanv(GL_COLOR_WRITEMASK, colorMask);
    417     ::glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    418     if (m_attrs.depth) {
    419         ::glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
    420         ::glDepthMask(GL_TRUE);
    421         clearMask |= GL_DEPTH_BUFFER_BIT;
    422     }
    423     if (m_attrs.stencil) {
    424         ::glGetBooleanv(GL_STENCIL_WRITEMASK, &stencilMask);
    425         ::glStencilMask(GL_TRUE);
    426         clearMask |= GL_STENCIL_BUFFER_BIT;
    427     }
    428     isScissorEnabled = ::glIsEnabled(GL_SCISSOR_TEST);
    429     ::glDisable(GL_SCISSOR_TEST);
    430     isDitherEnabled = ::glIsEnabled(GL_DITHER);
    431     ::glDisable(GL_DITHER);
    432 
    433     ::glClear(clearMask);
    434 
    435     ::glColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
    436     if (m_attrs.depth)
    437         ::glDepthMask(depthMask);
    438     if (m_attrs.stencil)
    439         ::glStencilMask(stencilMask);
    440     if (isScissorEnabled)
    441         ::glEnable(GL_SCISSOR_TEST);
    442     else
    443         ::glDisable(GL_SCISSOR_TEST);
    444     if (isDitherEnabled)
    445         ::glEnable(GL_DITHER);
    446     else
    447         ::glDisable(GL_DITHER);
    448 
    449     if (mustRestoreFBO)
    450         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
    451 
    452     ::glFlush();
    453 }
    454 
    455 static inline void ensureContext(CGLContextObj context)
    456 {
    457     if (!context)
    458         return;
    459        
    460     CGLContextObj currentContext = CGLGetCurrentContext();
    461     if (currentContext != context)
    462         CGLSetCurrentContext(context);
    463 }
    464 
    465 void GraphicsContext3D::prepareTexture()
    466 {
    467     ensureContext(m_contextObj);
    468     if (m_attrs.antialias) {
    469         ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
    470         ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
    471         ::glBlitFramebufferEXT(0, 0, m_currentWidth, m_currentHeight, 0, 0, m_currentWidth, m_currentHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
    472         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_boundFBO);
    473     }
    474     ::glFinish();
    475 }
    476 
    477 void GraphicsContext3D::activeTexture(unsigned long texture)
    478 {
    479     ensureContext(m_contextObj);
    480     ::glActiveTexture(texture);
    481 }
    482 
    483 void GraphicsContext3D::attachShader(Platform3DObject program, Platform3DObject shader)
    484 {
    485     ASSERT(program);
    486     ASSERT(shader);
    487     ensureContext(m_contextObj);
    488     ::glAttachShader((GLuint) program, (GLuint) shader);
    489 }
    490 
    491 void GraphicsContext3D::bindAttribLocation(Platform3DObject program, unsigned long index, const String& name)
    492 {
    493     ASSERT(program);
    494     ensureContext(m_contextObj);
    495     ::glBindAttribLocation((GLuint) program, index, name.utf8().data());
    496 }
    497 
    498 void GraphicsContext3D::bindBuffer(unsigned long target, Platform3DObject buffer)
    499 {
    500     ensureContext(m_contextObj);
    501     ::glBindBuffer(target, (GLuint) buffer);
    502 }
    503 
    504 
    505 void GraphicsContext3D::bindFramebuffer(unsigned long target, Platform3DObject buffer)
    506 {
    507     ensureContext(m_contextObj);
    508     GLuint fbo;
    509     if (buffer)
    510         fbo = (GLuint)buffer;
    511     else
    512         fbo = (m_attrs.antialias ? m_multisampleFBO : m_fbo);
    513     if (fbo != m_boundFBO) {
    514         ::glBindFramebufferEXT(target, fbo);
    515         m_boundFBO = fbo;
    516     }
    517 }
    518 
    519 void GraphicsContext3D::bindRenderbuffer(unsigned long target, Platform3DObject renderbuffer)
    520 {
    521     ensureContext(m_contextObj);
    522     ::glBindRenderbufferEXT(target, (GLuint) renderbuffer);
    523 }
    524 
    525 
    526 void GraphicsContext3D::bindTexture(unsigned long target, Platform3DObject texture)
    527 {
    528     ensureContext(m_contextObj);
    529     ::glBindTexture(target, (GLuint) texture);
    530 }
    531 
    532 void GraphicsContext3D::blendColor(double red, double green, double blue, double alpha)
    533 {
    534     ensureContext(m_contextObj);
    535     ::glBlendColor(static_cast<float>(red), static_cast<float>(green), static_cast<float>(blue), static_cast<float>(alpha));
    536 }
    537 
    538 void GraphicsContext3D::blendEquation( unsigned long mode )
    539 {
    540     ensureContext(m_contextObj);
    541     ::glBlendEquation(mode);
    542 }
    543 
    544 void GraphicsContext3D::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha)
    545 {
    546     ensureContext(m_contextObj);
    547     ::glBlendEquationSeparate(modeRGB, modeAlpha);
    548 }
    549 
    550 
    551 void GraphicsContext3D::blendFunc(unsigned long sfactor, unsigned long dfactor)
    552 {
    553     ensureContext(m_contextObj);
    554     ::glBlendFunc(sfactor, dfactor);
    555 }       
    556 
    557 void GraphicsContext3D::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha)
    558 {
    559     ensureContext(m_contextObj);
    560     ::glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
    561 }
    562 
    563 void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long usage)
    564 {
    565     ensureContext(m_contextObj);
    566     ::glBufferData(target, size, 0, usage);
    567 }
    568 
    569 void GraphicsContext3D::bufferData(unsigned long target, int size, const void* data, unsigned long usage)
    570 {
    571     ensureContext(m_contextObj);
    572     ::glBufferData(target, size, data, usage);
    573 }
    574 
    575 void GraphicsContext3D::bufferSubData(unsigned long target, long offset, int size, const void* data)
    576 {
    577     ensureContext(m_contextObj);
    578     ::glBufferSubData(target, offset, size, data);
    579 }
    580 
    581 unsigned long GraphicsContext3D::checkFramebufferStatus(unsigned long target)
    582 {
    583     ensureContext(m_contextObj);
    584     return ::glCheckFramebufferStatusEXT(target);
    585 }
    586 
    587 void GraphicsContext3D::clearColor(double r, double g, double b, double a)
    588 {
    589     ensureContext(m_contextObj);
    590     ::glClearColor(static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a));
    591 }
    592 
    593 void GraphicsContext3D::clear(unsigned long mask)
    594 {
    595     ensureContext(m_contextObj);
    596     ::glClear(mask);
    597 }
    598 
    599 void GraphicsContext3D::clearDepth(double depth)
    600 {
    601     ensureContext(m_contextObj);
    602     ::glClearDepth(depth);
    603 }
    604 
    605 void GraphicsContext3D::clearStencil(long s)
    606 {
    607     ensureContext(m_contextObj);
    608     ::glClearStencil(s);
    609 }
    610 
    611 void GraphicsContext3D::colorMask(bool red, bool green, bool blue, bool alpha)
    612 {
    613     ensureContext(m_contextObj);
    614     ::glColorMask(red, green, blue, alpha);
    615 }
    616 
    617 void GraphicsContext3D::compileShader(Platform3DObject shader)
    618 {
    619     ASSERT(shader);
    620     ensureContext(m_contextObj);
    621 
    622     int GLshaderType;
    623     ANGLEShaderType shaderType;
    624 
    625     glGetShaderiv(shader, SHADER_TYPE, &GLshaderType);
    626    
    627     if (GLshaderType == VERTEX_SHADER)
    628         shaderType = SHADER_TYPE_VERTEX;
    629     else if (GLshaderType == FRAGMENT_SHADER)
    630         shaderType = SHADER_TYPE_FRAGMENT;
    631     else
    632         return; // Invalid shader type.
    633 
    634     HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader);
    635 
    636     if (result == m_shaderSourceMap.end())
    637         return;
    638 
    639     ShaderSourceEntry& entry = result->second;
    640 
    641     String translatedShaderSource;
    642     String shaderInfoLog;
    643 
    644     bool isValid = m_compiler.validateShaderSource(entry.source.utf8().data(), shaderType, translatedShaderSource, shaderInfoLog);
    645 
    646     entry.log = shaderInfoLog;
    647     entry.isValid = isValid;
    648 
    649     if (!isValid)
    650         return; // Shader didn't validate, don't move forward with compiling translated source   
    651 
    652     int translatedShaderLength = translatedShaderSource.length();
    653 
    654     const CString& translatedShaderCString = translatedShaderSource.utf8();
    655     const char* translatedShaderPtr = translatedShaderCString.data();
    656    
    657     ::glShaderSource((GLuint) shader, 1, &translatedShaderPtr, &translatedShaderLength);
    658    
    659     ::glCompileShader((GLuint) shader);
    660    
    661     int GLCompileSuccess;
    662    
    663     ::glGetShaderiv((GLuint) shader, COMPILE_STATUS, &GLCompileSuccess);
    664    
    665     // ASSERT that ANGLE generated GLSL will be accepted by OpenGL
    666     ASSERT(GLCompileSuccess == GL_TRUE);
    667 }
    668 
    669 void GraphicsContext3D::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border)
    670 {
    671     ensureContext(m_contextObj);
    672     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
    673         ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
    674         ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
    675         ::glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
    676         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    677     }
    678     ::glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
    679     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
    680         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
    681 }
    682 
    683 void GraphicsContext3D::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height)
    684 {
    685     ensureContext(m_contextObj);
    686     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
    687         ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
    688         ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
    689         ::glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
    690         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    691     }
    692     ::glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
    693     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
    694         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
    695 }
    696 
    697 void GraphicsContext3D::cullFace(unsigned long mode)
    698 {
    699     ensureContext(m_contextObj);
    700     ::glCullFace(mode);
    701 }
    702 
    703 void GraphicsContext3D::depthFunc(unsigned long func)
    704 {
    705     ensureContext(m_contextObj);
    706     ::glDepthFunc(func);
    707 }
    708 
    709 void GraphicsContext3D::depthMask(bool flag)
    710 {
    711     ensureContext(m_contextObj);
    712     ::glDepthMask(flag);
    713 }
    714 
    715 void GraphicsContext3D::depthRange(double zNear, double zFar)
    716 {
    717     ensureContext(m_contextObj);
    718     ::glDepthRange(zNear, zFar);
    719 }
    720 
    721 void GraphicsContext3D::detachShader(Platform3DObject program, Platform3DObject shader)
    722 {
    723     ASSERT(program);
    724     ASSERT(shader);
    725     ensureContext(m_contextObj);
    726     ::glDetachShader((GLuint) program, (GLuint) shader);
    727 }
    728 
    729 void GraphicsContext3D::disable(unsigned long cap)
    730 {
    731     ensureContext(m_contextObj);
    732     ::glDisable(cap);
    733 }
    734 
    735 void GraphicsContext3D::disableVertexAttribArray(unsigned long index)
    736 {
    737     ensureContext(m_contextObj);
    738     ::glDisableVertexAttribArray(index);
    739 }
    740 
    741 void GraphicsContext3D::drawArrays(unsigned long mode, long first, long count)
    742 {
    743     ensureContext(m_contextObj);
    744     ::glDrawArrays(mode, first, count);
    745 }
    746 
    747 void GraphicsContext3D::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset)
    748 {
    749     ensureContext(m_contextObj);
    750     ::glDrawElements(mode, count, type, reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
    751 }
    752 
    753 void GraphicsContext3D::enable(unsigned long cap)
    754 {
    755     ensureContext(m_contextObj);
    756     ::glEnable(cap);
    757 }
    758 
    759 void GraphicsContext3D::enableVertexAttribArray(unsigned long index)
    760 {
    761     ensureContext(m_contextObj);
    762     ::glEnableVertexAttribArray(index);
    763 }
    764 
    765 void GraphicsContext3D::finish()
    766 {
    767     ensureContext(m_contextObj);
    768     ::glFinish();
    769 }
    770 
    771 void GraphicsContext3D::flush()
    772 {
    773     ensureContext(m_contextObj);
    774     ::glFlush();
    775 }
    776 
    777 void GraphicsContext3D::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, Platform3DObject buffer)
    778 {
    779     ensureContext(m_contextObj);
    780     GLuint renderbuffer = (GLuint) buffer;
    781     if (attachment == DEPTH_STENCIL_ATTACHMENT) {
    782         ::glFramebufferRenderbufferEXT(target, DEPTH_ATTACHMENT, renderbuffertarget, renderbuffer);
    783         ::glFramebufferRenderbufferEXT(target, STENCIL_ATTACHMENT, renderbuffertarget, renderbuffer);
    784     } else
    785         ::glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer);
    786 }
    787 
    788 void GraphicsContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, Platform3DObject texture, long level)
    789 {
    790     ensureContext(m_contextObj);
    791     ::glFramebufferTexture2DEXT(target, attachment, textarget, (GLuint) texture, level);
    792 }
    793 
    794 void GraphicsContext3D::frontFace(unsigned long mode)
    795 {
    796     ensureContext(m_contextObj);
    797     ::glFrontFace(mode);
    798 }
    799 
    800 void GraphicsContext3D::generateMipmap(unsigned long target)
    801 {
    802     ensureContext(m_contextObj);
    803     ::glGenerateMipmapEXT(target);
    804 }
    805 
    806 bool GraphicsContext3D::getActiveAttrib(Platform3DObject program, unsigned long index, ActiveInfo& info)
    807 {
    808     if (!program) {
    809         synthesizeGLError(INVALID_VALUE);
    810         return false;
    811     }
    812     ensureContext(m_contextObj);
    813     GLint maxAttributeSize = 0;
    814     ::glGetProgramiv(static_cast<GLuint>(program), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeSize);
    815     GLchar name[maxAttributeSize]; // GL_ACTIVE_ATTRIBUTE_MAX_LENGTH includes null termination
    816     GLsizei nameLength = 0;
    817     GLint size = 0;
    818     GLenum type = 0;
    819     ::glGetActiveAttrib(static_cast<GLuint>(program), index, maxAttributeSize, &nameLength, &size, &type, name);
    820     if (!nameLength)
    821         return false;
    822     info.name = String(name, nameLength);
    823     info.type = type;
    824     info.size = size;
    825     return true;
    826 }
    827    
    828 bool GraphicsContext3D::getActiveUniform(Platform3DObject program, unsigned long index, ActiveInfo& info)
    829 {
    830     if (!program) {
    831         synthesizeGLError(INVALID_VALUE);
    832         return false;
    833     }
    834     ensureContext(m_contextObj);
    835     GLint maxUniformSize = 0;
    836     ::glGetProgramiv(static_cast<GLuint>(program), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformSize);
    837     GLchar name[maxUniformSize]; // GL_ACTIVE_UNIFORM_MAX_LENGTH includes null termination
    838     GLsizei nameLength = 0;
    839     GLint size = 0;
    840     GLenum type = 0;
    841     ::glGetActiveUniform(static_cast<GLuint>(program), index, maxUniformSize, &nameLength, &size, &type, name);
    842     if (!nameLength)
    843         return false;
    844     info.name = String(name, nameLength);
    845     info.type = type;
    846     info.size = size;
    847     return true;
    848 }
    849 
    850 void GraphicsContext3D::getAttachedShaders(Platform3DObject program, int maxCount, int* count, unsigned int* shaders)
    851 {
    852     if (!program) {
    853         synthesizeGLError(INVALID_VALUE);
    854         return;
    855     }
    856     ensureContext(m_contextObj);
    857     ::glGetAttachedShaders(static_cast<GLuint>(program), maxCount, count, shaders);
    858 }
    859 
    860 int GraphicsContext3D::getAttribLocation(Platform3DObject program, const String& name)
    861 {
    862     if (!program)
    863         return -1;
    864    
    865     ensureContext(m_contextObj);
    866     return ::glGetAttribLocation((GLuint) program, name.utf8().data());
    867 }
    868 
    869 GraphicsContext3D::Attributes GraphicsContext3D::getContextAttributes()
    870 {
    871     return m_attrs;
    872 }
    873 
    874 unsigned long GraphicsContext3D::getError()
    875 {
    876     if (m_syntheticErrors.size() > 0) {
    877         ListHashSet<unsigned long>::iterator iter = m_syntheticErrors.begin();
    878         unsigned long err = *iter;
    879         m_syntheticErrors.remove(iter);
    880         return err;
    881     }
    882 
    883     ensureContext(m_contextObj);
    884     return ::glGetError();
    885 }
    886 
    887 String GraphicsContext3D::getString(unsigned long name)
    888 {
    889     ensureContext(m_contextObj);
    890     return String((const char*) ::glGetString(name));
    891 }
    892 
    893 void GraphicsContext3D::hint(unsigned long target, unsigned long mode)
    894 {
    895     ensureContext(m_contextObj);
    896     ::glHint(target, mode);
    897 }
    898 
    899 bool GraphicsContext3D::isBuffer(Platform3DObject buffer)
    900 {
    901     if (!buffer)
    902         return false;
    903    
    904     ensureContext(m_contextObj);
    905     return ::glIsBuffer((GLuint) buffer);
    906 }
    907 
    908 bool GraphicsContext3D::isEnabled(unsigned long cap)
    909 {
    910     ensureContext(m_contextObj);
    911     return ::glIsEnabled(cap);
    912 }
    913 
    914 bool GraphicsContext3D::isFramebuffer(Platform3DObject framebuffer)
    915 {
    916     if (!framebuffer)
    917         return false;
    918    
    919     ensureContext(m_contextObj);
    920     return ::glIsFramebufferEXT((GLuint) framebuffer);
    921 }
    922 
    923 bool GraphicsContext3D::isProgram(Platform3DObject program)
    924 {
    925     if (!program)
    926         return false;
    927    
    928     ensureContext(m_contextObj);
    929     return ::glIsProgram((GLuint) program);
    930 }
    931 
    932 bool GraphicsContext3D::isRenderbuffer(Platform3DObject renderbuffer)
    933 {
    934     if (!renderbuffer)
    935         return false;
    936    
    937     ensureContext(m_contextObj);
    938     return ::glIsRenderbufferEXT((GLuint) renderbuffer);
    939 }
    940 
    941 bool GraphicsContext3D::isShader(Platform3DObject shader)
    942 {
    943     if (!shader)
    944         return false;
    945    
    946     ensureContext(m_contextObj);
    947     return ::glIsShader((GLuint) shader);
    948 }
    949 
    950 bool GraphicsContext3D::isTexture(Platform3DObject texture)
    951 {
    952     if (!texture)
    953         return false;
    954    
    955     ensureContext(m_contextObj);
    956     return ::glIsTexture((GLuint) texture);
    957 }
    958 
    959 void GraphicsContext3D::lineWidth(double width)
    960 {
    961     ensureContext(m_contextObj);
    962     ::glLineWidth(static_cast<float>(width));
    963 }
    964 
    965 void GraphicsContext3D::linkProgram(Platform3DObject program)
    966 {
    967     ASSERT(program);
    968     ensureContext(m_contextObj);
    969     ::glLinkProgram((GLuint) program);
    970 }
    971 
    972 void GraphicsContext3D::pixelStorei(unsigned long pname, long param)
    973 {
    974     ensureContext(m_contextObj);
    975     ::glPixelStorei(pname, param);
    976 }
    977 
    978 void GraphicsContext3D::polygonOffset(double factor, double units)
    979 {
    980     ensureContext(m_contextObj);
    981     ::glPolygonOffset(static_cast<float>(factor), static_cast<float>(units));
    982 }
    983 
    984 void GraphicsContext3D::readPixels(long x, long y, unsigned long width, unsigned long height, unsigned long format, unsigned long type, void* data)
    985 {
    986     // FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
    987     // all previous rendering calls should be done before reading pixels.
    988     ensureContext(m_contextObj);
    989     ::glFlush();
    990     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) {
    991         ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO);
    992         ::glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_fbo);
    993         ::glBlitFramebufferEXT(x, y, x + width, y + height, x, y, x + width, y + height, GL_COLOR_BUFFER_BIT, GL_LINEAR);
    994         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
    995         ::glFlush();
    996     }
    997     ::glReadPixels(x, y, width, height, format, type, data);
    998     if (m_attrs.antialias && m_boundFBO == m_multisampleFBO)
    999         ::glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_multisampleFBO);
    1000 }
    1001 
    1002 void GraphicsContext3D::releaseShaderCompiler()
    1003 {
    1004     // FIXME: This is not implemented on desktop OpenGL. We need to have ifdefs for the different GL variants
    1005     ensureContext(m_contextObj);
    1006     //::glReleaseShaderCompiler();
    1007 }
    1008 
    1009 void GraphicsContext3D::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height)
    1010 {
    1011     ensureContext(m_contextObj);
    1012     switch (internalformat) {
    1013     case DEPTH_STENCIL:
    1014         internalformat = GL_DEPTH24_STENCIL8_EXT;
    1015         break;
    1016     case DEPTH_COMPONENT16:
    1017         internalformat = GL_DEPTH_COMPONENT;
    1018         break;
    1019     case RGBA4:
    1020     case RGB5_A1:
    1021         internalformat = GL_RGBA;
    1022         break;
    1023     case RGB565:
    1024         internalformat = GL_RGB;
    1025         break;
    1026     }
    1027     ::glRenderbufferStorageEXT(target, internalformat, width, height);
    1028 }
    1029 
    1030 void GraphicsContext3D::sampleCoverage(double value, bool invert)
    1031 {
    1032     ensureContext(m_contextObj);
    1033     ::glSampleCoverage(static_cast<float>(value), invert);
    1034 }
    1035 
    1036 void GraphicsContext3D::scissor(long x, long y, unsigned long width, unsigned long height)
    1037 {
    1038     ensureContext(m_contextObj);
    1039     ::glScissor(x, y, width, height);
    1040 }
    1041 
    1042 void GraphicsContext3D::shaderSource(Platform3DObject shader, const String& string)
    1043 {
    1044     ASSERT(shader);
    1045    
    1046     ensureContext(m_contextObj);
    1047 
    1048     ShaderSourceEntry entry;
    1049 
    1050     entry.source = string;
    1051 
    1052     m_shaderSourceMap.set(shader, entry);
    1053 }
    1054 
    1055 void GraphicsContext3D::stencilFunc(unsigned long func, long ref, unsigned long mask)
    1056 {
    1057     ensureContext(m_contextObj);
    1058     ::glStencilFunc(func, ref, mask);
    1059 }
    1060 
    1061 void GraphicsContext3D::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask)
    1062 {
    1063     ensureContext(m_contextObj);
    1064     ::glStencilFuncSeparate(face, func, ref, mask);
    1065 }
    1066 
    1067 void GraphicsContext3D::stencilMask(unsigned long mask)
    1068 {
    1069     ensureContext(m_contextObj);
    1070     ::glStencilMask(mask);
    1071 }
    1072 
    1073 void GraphicsContext3D::stencilMaskSeparate(unsigned long face, unsigned long mask)
    1074 {
    1075     ensureContext(m_contextObj);
    1076     ::glStencilMaskSeparate(face, mask);
    1077 }
    1078 
    1079 void GraphicsContext3D::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass)
    1080 {
    1081     ensureContext(m_contextObj);
    1082     ::glStencilOp(fail, zfail, zpass);
    1083 }
    1084 
    1085 void GraphicsContext3D::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass)
    1086 {
    1087     ensureContext(m_contextObj);
    1088     ::glStencilOpSeparate(face, fail, zfail, zpass);
    1089 }
    1090 
    1091 void GraphicsContext3D::texParameterf(unsigned target, unsigned pname, float value)
    1092 {
    1093     ensureContext(m_contextObj);
    1094     ::glTexParameterf(target, pname, static_cast<float>(value));
    1095 }
    1096 
    1097 void GraphicsContext3D::texParameteri(unsigned target, unsigned pname, int value)
    1098 {
    1099     ensureContext(m_contextObj);
    1100     ::glTexParameteri(target, pname, static_cast<float>(value));
    1101 }
    1102 
    1103 void GraphicsContext3D::uniform1f(long location, float v0)
    1104 {
    1105     ensureContext(m_contextObj);
    1106     ::glUniform1f(location, v0);
    1107 }
    1108 
    1109 void GraphicsContext3D::uniform1fv(long location, float* array, int size)
    1110 {
    1111     ensureContext(m_contextObj);
    1112     ::glUniform1fv(location, size, array);
    1113 }
    1114 
    1115 void GraphicsContext3D::uniform2f(long location, float v0, float v1)
    1116 {
    1117     ensureContext(m_contextObj);
    1118     ::glUniform2f(location, v0, v1);
    1119 }
    1120 
    1121 void GraphicsContext3D::uniform2fv(long location, float* array, int size)
    1122 {
    1123     // FIXME: length needs to be a multiple of 2
    1124     ensureContext(m_contextObj);
    1125     ::glUniform2fv(location, size, array);
    1126 }
    1127 
    1128 void GraphicsContext3D::uniform3f(long location, float v0, float v1, float v2)
    1129 {
    1130     ensureContext(m_contextObj);
    1131     ::glUniform3f(location, v0, v1, v2);
    1132 }
    1133 
    1134 void GraphicsContext3D::uniform3fv(long location, float* array, int size)
    1135 {
    1136     // FIXME: length needs to be a multiple of 3
    1137     ensureContext(m_contextObj);
    1138     ::glUniform3fv(location, size, array);
    1139 }
    1140 
    1141 void GraphicsContext3D::uniform4f(long location, float v0, float v1, float v2, float v3)
    1142 {
    1143     ensureContext(m_contextObj);
    1144     ::glUniform4f(location, v0, v1, v2, v3);
    1145 }
    1146 
    1147 void GraphicsContext3D::uniform4fv(long location, float* array, int size)
    1148 {
    1149     // FIXME: length needs to be a multiple of 4
    1150     ensureContext(m_contextObj);
    1151     ::glUniform4fv(location, size, array);
    1152 }
    1153 
    1154 void GraphicsContext3D::uniform1i(long location, int v0)
    1155 {
    1156     ensureContext(m_contextObj);
    1157     ::glUniform1i(location, v0);
    1158 }
    1159 
    1160 void GraphicsContext3D::uniform1iv(long location, int* array, int size)
    1161 {
    1162     ensureContext(m_contextObj);
    1163     ::glUniform1iv(location, size, array);
    1164 }
    1165 
    1166 void GraphicsContext3D::uniform2i(long location, int v0, int v1)
    1167 {
    1168     ensureContext(m_contextObj);
    1169     ::glUniform2i(location, v0, v1);
    1170 }
    1171 
    1172 void GraphicsContext3D::uniform2iv(long location, int* array, int size)
    1173 {
    1174     // FIXME: length needs to be a multiple of 2
    1175     ensureContext(m_contextObj);
    1176     ::glUniform2iv(location, size, array);
    1177 }
    1178 
    1179 void GraphicsContext3D::uniform3i(long location, int v0, int v1, int v2)
    1180 {
    1181     ensureContext(m_contextObj);
    1182     ::glUniform3i(location, v0, v1, v2);
    1183 }
    1184 
    1185 void GraphicsContext3D::uniform3iv(long location, int* array, int size)
    1186 {
    1187     // FIXME: length needs to be a multiple of 3
    1188     ensureContext(m_contextObj);
    1189     ::glUniform3iv(location, size, array);
    1190 }
    1191 
    1192 void GraphicsContext3D::uniform4i(long location, int v0, int v1, int v2, int v3)
    1193 {
    1194     ensureContext(m_contextObj);
    1195     ::glUniform4i(location, v0, v1, v2, v3);
    1196 }
    1197 
    1198 void GraphicsContext3D::uniform4iv(long location, int* array, int size)
    1199 {
    1200     // FIXME: length needs to be a multiple of 4
    1201     ensureContext(m_contextObj);
    1202     ::glUniform4iv(location, size, array);
    1203 }
    1204 
    1205 void GraphicsContext3D::uniformMatrix2fv(long location, bool transpose, float* array, int size)
    1206 {
    1207     // FIXME: length needs to be a multiple of 4
    1208     ensureContext(m_contextObj);
    1209     ::glUniformMatrix2fv(location, size, transpose, array);
    1210 }
    1211 
    1212 void GraphicsContext3D::uniformMatrix3fv(long location, bool transpose, float* array, int size)
    1213 {
    1214     // FIXME: length needs to be a multiple of 9
    1215     ensureContext(m_contextObj);
    1216     ::glUniformMatrix3fv(location, size, transpose, array);
    1217 }
    1218 
    1219 void GraphicsContext3D::uniformMatrix4fv(long location, bool transpose, float* array, int size)
    1220 {
    1221     // FIXME: length needs to be a multiple of 16
    1222     ensureContext(m_contextObj);
    1223     ::glUniformMatrix4fv(location, size, transpose, array);
    1224 }
    1225 
    1226 void GraphicsContext3D::useProgram(Platform3DObject program)
    1227 {
    1228     ensureContext(m_contextObj);
    1229     ::glUseProgram((GLuint) program);
    1230 }
    1231 
    1232 void GraphicsContext3D::validateProgram(Platform3DObject program)
    1233 {
    1234     ASSERT(program);
    1235    
    1236     ensureContext(m_contextObj);
    1237     ::glValidateProgram((GLuint) program);
    1238 }
    1239 
    1240 void GraphicsContext3D::vertexAttrib1f(unsigned long indx, float v0)
    1241 {
    1242     ensureContext(m_contextObj);
    1243     ::glVertexAttrib1f(indx, v0);
    1244 }
    1245 
    1246 void GraphicsContext3D::vertexAttrib1fv(unsigned long indx, float* array)
    1247 {
    1248     ensureContext(m_contextObj);
    1249     ::glVertexAttrib1fv(indx, array);
    1250 }
    1251 
    1252 void GraphicsContext3D::vertexAttrib2f(unsigned long indx, float v0, float v1)
    1253 {
    1254     ensureContext(m_contextObj);
    1255     ::glVertexAttrib2f(indx, v0, v1);
    1256 }
    1257 
    1258 void GraphicsContext3D::vertexAttrib2fv(unsigned long indx, float* array)
    1259 {
    1260     ensureContext(m_contextObj);
    1261     ::glVertexAttrib2fv(indx, array);
    1262 }
    1263 
    1264 void GraphicsContext3D::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2)
    1265 {
    1266     ensureContext(m_contextObj);
    1267     ::glVertexAttrib3f(indx, v0, v1, v2);
    1268 }
    1269 
    1270 void GraphicsContext3D::vertexAttrib3fv(unsigned long indx, float* array)
    1271 {
    1272     ensureContext(m_contextObj);
    1273     ::glVertexAttrib3fv(indx, array);
    1274 }
    1275 
    1276 void GraphicsContext3D::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3)
    1277 {
    1278     ensureContext(m_contextObj);
    1279     ::glVertexAttrib4f(indx, v0, v1, v2, v3);
    1280 }
    1281 
    1282 void GraphicsContext3D::vertexAttrib4fv(unsigned long indx, float* array)
    1283 {
    1284     ensureContext(m_contextObj);
    1285     ::glVertexAttrib4fv(indx, array);
    1286 }
    1287 
    1288 void GraphicsContext3D::vertexAttribPointer(unsigned long indx, int size, int type, bool normalized, unsigned long stride, unsigned long offset)
    1289 {
    1290     ensureContext(m_contextObj);
    1291     ::glVertexAttribPointer(indx, size, type, normalized, stride, reinterpret_cast<void*>(static_cast<intptr_t>(offset)));
    1292 }
    1293 
    1294 void GraphicsContext3D::viewport(long x, long y, unsigned long width, unsigned long height)
    1295 {
    1296     ensureContext(m_contextObj);
    1297     ::glViewport(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height));
    1298 }
    1299 
    1300 void GraphicsContext3D::getBooleanv(unsigned long pname, unsigned char* value)
    1301 {
    1302     ensureContext(m_contextObj);
    1303     ::glGetBooleanv(pname, value);
    1304 }
    1305 
    1306 void GraphicsContext3D::getBufferParameteriv(unsigned long target, unsigned long pname, int* value)
    1307 {
    1308     ensureContext(m_contextObj);
    1309     ::glGetBufferParameteriv(target, pname, value);
    1310 }
    1311 
    1312 void GraphicsContext3D::getFloatv(unsigned long pname, float* value)
    1313 {
    1314     ensureContext(m_contextObj);
    1315     ::glGetFloatv(pname, value);
    1316 }
    1317 
    1318 void GraphicsContext3D::getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname, int* value)
    1319 {
    1320     ensureContext(m_contextObj);
    1321     if (attachment == DEPTH_STENCIL_ATTACHMENT)
    1322         attachment = DEPTH_ATTACHMENT; // Or STENCIL_ATTACHMENT, either works.
    1323     ::glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, value);
    1324 }
    1325 
    1326 void GraphicsContext3D::getIntegerv(unsigned long pname, int* value)
    1327 {
    1328     // Need to emulate IMPLEMENTATION_COLOR_READ_FORMAT/TYPE for GL.  Any valid
    1329     // combination should work, but GL_RGB/GL_UNSIGNED_BYTE might be the most
    1330     // useful for desktop WebGL users.
    1331     // Need to emulate MAX_FRAGMENT/VERTEX_UNIFORM_VECTORS and MAX_VARYING_VECTORS
    1332     // because desktop GL's corresponding queries return the number of components
    1333     // whereas GLES2 return the number of vectors (each vector has 4 components).
    1334     // Therefore, the value returned by desktop GL needs to be divided by 4.
    1335     ensureContext(m_contextObj);
    1336     switch (pname) {
    1337     case IMPLEMENTATION_COLOR_READ_FORMAT:
    1338         *value = GL_RGB;
    1339         break;
    1340     case IMPLEMENTATION_COLOR_READ_TYPE:
    1341         *value = GL_UNSIGNED_BYTE;
    1342         break;
    1343     case MAX_FRAGMENT_UNIFORM_VECTORS:
    1344         ::glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, value);
    1345         *value /= 4;
    1346         break;
    1347     case MAX_VERTEX_UNIFORM_VECTORS:
    1348         ::glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, value);
    1349         *value /= 4;
    1350         break;
    1351     case MAX_VARYING_VECTORS:
    1352         ::glGetIntegerv(GL_MAX_VARYING_FLOATS, value);
    1353         *value /= 4;
    1354         break;
    1355     default:
    1356         ::glGetIntegerv(pname, value);
    1357     }
    1358 }
    1359 
    1360 void GraphicsContext3D::getProgramiv(Platform3DObject program, unsigned long pname, int* value)
    1361 {
    1362     ensureContext(m_contextObj);
    1363     ::glGetProgramiv((GLuint) program, pname, value);
    1364 }
    1365 
    1366 String GraphicsContext3D::getProgramInfoLog(Platform3DObject program)
    1367 {
    1368     ASSERT(program);
    1369    
    1370     ensureContext(m_contextObj);
    1371     GLint length;
    1372     ::glGetProgramiv((GLuint) program, GL_INFO_LOG_LENGTH, &length);
    1373    
    1374     GLsizei size;
    1375     GLchar* info = (GLchar*) fastMalloc(length);
    1376     if (!info)
    1377         return "";
    1378 
    1379     ::glGetProgramInfoLog((GLuint) program, length, &size, info);
    1380     String s(info);
    1381     fastFree(info);
    1382     return s;
    1383 }
    1384 
    1385 void GraphicsContext3D::getRenderbufferParameteriv(unsigned long target, unsigned long pname, int* value)
    1386 {
    1387     ensureContext(m_contextObj);
    1388     ::glGetRenderbufferParameterivEXT(target, pname, value);
    1389 }
    1390 
    1391 void GraphicsContext3D::getShaderiv(Platform3DObject shader, unsigned long pname, int* value)
    1392 {
    1393     ASSERT(shader);
    1394    
    1395     ensureContext(m_contextObj);
    1396    
    1397     HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader);
    1398    
    1399     switch (pname) {
    1400         case DELETE_STATUS:
    1401         case SHADER_TYPE:
    1402             // Let OpenGL handle these.
    1403        
    1404             ::glGetShaderiv((GLuint) shader, pname, value);
    1405             break;
    1406 
    1407         case COMPILE_STATUS:
    1408             if (result == m_shaderSourceMap.end()) {
    1409                 (*value) = static_cast<int>(false);
    1410                 return;
    1411             }
    1412                
    1413             (*value) = static_cast<int>(result->second.isValid);
    1414             break;
    1415            
    1416         case INFO_LOG_LENGTH:
    1417             if (result == m_shaderSourceMap.end()) {
    1418                 (*value) = 0;
    1419                 return;
    1420             }
    1421            
    1422             (*value) = getShaderInfoLog(shader).length();
    1423             break;
    1424            
    1425         case SHADER_SOURCE_LENGTH:
    1426             (*value) = getShaderSource(shader).length();
    1427             break;
    1428        
    1429         default:
    1430             synthesizeGLError(INVALID_ENUM);
    1431     }
    1432 }
    1433 
    1434 String GraphicsContext3D::getShaderInfoLog(Platform3DObject shader)
    1435 {
    1436     ASSERT(shader);
    1437 
    1438     ensureContext(m_contextObj);
    1439     GLint length;
    1440     ::glGetShaderiv((GLuint) shader, GL_INFO_LOG_LENGTH, &length);
    1441 
    1442     HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader);
    1443 
    1444     if (result == m_shaderSourceMap.end())
    1445          return "";
    1446 
    1447      ShaderSourceEntry entry = result->second;
    1448 
    1449      if (entry.isValid) {
    1450          GLint length;
    1451          ::glGetShaderiv((GLuint) shader, GL_INFO_LOG_LENGTH, &length);
    1452 
    1453          GLsizei size;
    1454          GLchar* info = (GLchar*) fastMalloc(length);
    1455          if (!info)
    1456              return "";
    1457 
    1458          ::glGetShaderInfoLog((GLuint) shader, length, &size, info);
    1459 
    1460          String s(info);
    1461          fastFree(info);
    1462          return s;
    1463      }
    1464      else {
    1465          return entry.log;
    1466      }
    1467 }
    1468 
    1469 String GraphicsContext3D::getShaderSource(Platform3DObject shader)
    1470 {
    1471     ASSERT(shader);
    1472 
    1473     ensureContext(m_contextObj);
    1474 
    1475     HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader);
    1476 
    1477     if (result == m_shaderSourceMap.end())
    1478         return "";
    1479 
    1480     return result->second.source;
    1481 }
    1482 
    1483 
    1484 void GraphicsContext3D::getTexParameterfv(unsigned long target, unsigned long pname, float* value)
    1485 {
    1486     ensureContext(m_contextObj);
    1487     ::glGetTexParameterfv(target, pname, value);
    1488 }
    1489 
    1490 void GraphicsContext3D::getTexParameteriv(unsigned long target, unsigned long pname, int* value)
    1491 {
    1492     ensureContext(m_contextObj);
    1493     ::glGetTexParameteriv(target, pname, value);
    1494 }
    1495 
    1496 void GraphicsContext3D::getUniformfv(Platform3DObject program, long location, float* value)
    1497 {
    1498     ensureContext(m_contextObj);
    1499     ::glGetUniformfv((GLuint) program, location, value);
    1500 }
    1501 
    1502 void GraphicsContext3D::getUniformiv(Platform3DObject program, long location, int* value)
    1503 {
    1504     ensureContext(m_contextObj);
    1505     ::glGetUniformiv((GLuint) program, location, value);
    1506 }
    1507 
    1508 long GraphicsContext3D::getUniformLocation(Platform3DObject program, const String& name)
    1509 {
    1510     ASSERT(program);
    1511    
    1512     ensureContext(m_contextObj);
    1513     return ::glGetUniformLocation((GLuint) program, name.utf8().data());
    1514 }
    1515 
    1516 void GraphicsContext3D::getVertexAttribfv(unsigned long index, unsigned long pname, float* value)
    1517 {
    1518     ensureContext(m_contextObj);
    1519     ::glGetVertexAttribfv(index, pname, value);
    1520 }
    1521 
    1522 void GraphicsContext3D::getVertexAttribiv(unsigned long index, unsigned long pname, int* value)
    1523 {
    1524     ensureContext(m_contextObj);
    1525     ::glGetVertexAttribiv(index, pname, value);
    1526 }
    1527 
    1528 long GraphicsContext3D::getVertexAttribOffset(unsigned long index, unsigned long pname)
    1529 {
    1530     ensureContext(m_contextObj);
    1531    
    1532     void* pointer;
    1533     ::glGetVertexAttribPointerv(index, pname, &pointer);
    1534     return reinterpret_cast<long>(pointer);
    1535 }
    1536 
    1537 int GraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels)
    1538 {
    1539     ensureContext(m_contextObj);
    1540 
    1541     ::glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
    1542     return 0;
    1543 }
    1544 
    1545 int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels)
    1546 {
    1547     ensureContext(m_contextObj);
    1548 
    1549     // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size
    1550     ::glTexSubImage2D(target, level, xoff, yoff, width, height, format, type, pixels);
    1551     return 0;
    1552 }
    1553 
    1554 unsigned GraphicsContext3D::createBuffer()
    1555 {
    1556     ensureContext(m_contextObj);
    1557     GLuint o;
    1558     glGenBuffers(1, &o);
    1559     return o;
    1560 }
    1561 
    1562 unsigned GraphicsContext3D::createFramebuffer()
    1563 {
    1564     ensureContext(m_contextObj);
    1565     GLuint o;
    1566     glGenFramebuffersEXT(1, &o);
    1567     return o;
    1568 }
    1569 
    1570 unsigned GraphicsContext3D::createProgram()
    1571 {
    1572     ensureContext(m_contextObj);
    1573     return glCreateProgram();
    1574 }
    1575 
    1576 unsigned GraphicsContext3D::createRenderbuffer()
    1577 {
    1578     ensureContext(m_contextObj);
    1579     GLuint o;
    1580     glGenRenderbuffersEXT(1, &o);
    1581     return o;
    1582 }
    1583 
    1584 unsigned GraphicsContext3D::createShader(unsigned long type)
    1585 {
    1586     ensureContext(m_contextObj);
    1587     return glCreateShader((type == FRAGMENT_SHADER) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER);
    1588 }
    1589 
    1590 unsigned GraphicsContext3D::createTexture()
    1591 {
    1592     ensureContext(m_contextObj);
    1593     GLuint o;
    1594     glGenTextures(1, &o);
    1595     return o;
    1596 }
    1597 
    1598 void GraphicsContext3D::deleteBuffer(unsigned buffer)
    1599 {
    1600     ensureContext(m_contextObj);
    1601     glDeleteBuffers(1, &buffer);
    1602 }
    1603 
    1604 void GraphicsContext3D::deleteFramebuffer(unsigned framebuffer)
    1605 {
    1606     ensureContext(m_contextObj);
    1607     glDeleteFramebuffersEXT(1, &framebuffer);
    1608 }
    1609 
    1610 void GraphicsContext3D::deleteProgram(unsigned program)
    1611 {
    1612     ensureContext(m_contextObj);
    1613     glDeleteProgram(program);
    1614 }
    1615 
    1616 void GraphicsContext3D::deleteRenderbuffer(unsigned renderbuffer)
    1617 {
    1618     ensureContext(m_contextObj);
    1619     glDeleteRenderbuffersEXT(1, &renderbuffer);
    1620 }
    1621 
    1622 void GraphicsContext3D::deleteShader(unsigned shader)
    1623 {
    1624     ensureContext(m_contextObj);
    1625     glDeleteShader(shader);
    1626 }
    1627 
    1628 void GraphicsContext3D::deleteTexture(unsigned texture)
    1629 {
    1630     ensureContext(m_contextObj);
    1631     glDeleteTextures(1, &texture);
    1632 }
    1633 
    1634 int GraphicsContext3D::sizeInBytes(int type)
    1635 {
    1636     switch (type) {
    1637         case GL_BYTE:
    1638             return sizeof(GLbyte);
    1639         case GL_UNSIGNED_BYTE:
    1640             return sizeof(GLubyte);
    1641         case GL_SHORT:
    1642             return sizeof(GLshort);
    1643         case GL_UNSIGNED_SHORT:
    1644             return sizeof(GLushort);
    1645         case GL_INT:
    1646             return sizeof(GLint);
    1647         case GL_UNSIGNED_INT:
    1648             return sizeof(GLuint);
    1649         case GL_FLOAT:
    1650             return sizeof(GLfloat);
    1651         default:
    1652             return 0;
    1653     }
    1654 }
    1655 
    1656 void GraphicsContext3D::synthesizeGLError(unsigned long error)
    1657 {
    1658     m_syntheticErrors.add(error);
    1659 }
     257   
    1660258
    1661259}
Note: See TracChangeset for help on using the changeset viewer.