Changeset 66781 in webkit
- Timestamp:
- Sep 3, 2010 5:49:40 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r66780 r66781 1 2010-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 1 157 2010-09-03 James Robinson <jamesr@chromium.org> 2 158 -
trunk/WebCore/WebCore.gypi
r66779 r66781 2600 2600 'platform/graphics/GraphicsContext.h', 2601 2601 'platform/graphics/GraphicsContext3D.cpp', 2602 'platform/graphics/GraphicsContext3DOpenGL.cpp', 2602 2603 'platform/graphics/GraphicsContext3D.h', 2603 2604 'platform/graphics/GraphicsContextPrivate.h', -
trunk/WebCore/WebCore.xcodeproj/project.pbxproj
r66774 r66781 5370 5370 FAC12CC41120DA6900DACC36 /* RenderMathMLSubSup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAC12CC21120DA6900DACC36 /* RenderMathMLSubSup.cpp */; }; 5371 5371 FAC12CC51120DA6900DACC36 /* RenderMathMLSubSup.h in Headers */ = {isa = PBXBuildFile; fileRef = FAC12CC31120DA6900DACC36 /* RenderMathMLSubSup.h */; }; 5372 FB58CB79122F153800878851 /* GraphicsContext3DOpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FB58CAEA1228586500878851 /* GraphicsContext3DOpenGL.cpp */; }; 5372 5373 FE6FD4880F676E5700092873 /* Coordinates.h in Headers */ = {isa = PBXBuildFile; fileRef = FE6FD4850F676E5700092873 /* Coordinates.h */; settings = {ATTRIBUTES = (Private, ); }; }; 5373 5374 FE6FD48D0F676E9300092873 /* JSCoordinates.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE6FD48B0F676E9300092873 /* JSCoordinates.cpp */; }; … … 11241 11242 FAC12CC21120DA6900DACC36 /* RenderMathMLSubSup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderMathMLSubSup.cpp; sourceTree = "<group>"; }; 11242 11243 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>"; }; 11243 11245 FE49EF970DC51462004266E1 /* DashboardSupportCSSPropertyNames.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DashboardSupportCSSPropertyNames.in; sourceTree = "<group>"; }; 11244 11246 FE6FD4850F676E5700092873 /* Coordinates.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Coordinates.h; sourceTree = "<group>"; }; … … 15912 15914 6E21C6BF1126338500A7BE02 /* GraphicsContext3D.cpp */, 15913 15915 49C7B9FB1042D3650009D447 /* GraphicsContext3D.h */, 15916 FB58CAEA1228586500878851 /* GraphicsContext3DOpenGL.cpp */, 15914 15917 A88FE3330E5EEE87008D8C0F /* GraphicsContextPrivate.h */, 15915 15918 0F580B090F12A2690051D689 /* GraphicsLayer.cpp */, … … 20492 20495 buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */; 20493 20496 compatibilityVersion = "Xcode 2.4"; 20497 developmentRegion = English; 20494 20498 hasScannedForEncodings = 1; 20495 20499 knownRegions = ( … … 22896 22900 898785F0122E1E87003AABDA /* JSFileException.cpp in Sources */, 22897 22901 898785F4122E1EAC003AABDA /* JSFileReaderSync.cpp in Sources */, 22902 FB58CB79122F153800878851 /* GraphicsContext3DOpenGL.cpp in Sources */, 22898 22903 ); 22899 22904 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebCore/html/canvas/WebGLObject.cpp
r65330 r66781 61 61 if (m_object) { 62 62 if (m_context) { 63 m_context->graphicsContext3D()-> makeContextCurrent();63 m_context->graphicsContext3D()->ensureContext(); 64 64 deleteObjectImpl(m_object); 65 65 } -
trunk/WebCore/platform/graphics/ANGLEWebKitBridge.h
r65446 r66781 39 39 }; 40 40 41 41 42 class ANGLEWebKitBridge { 42 43 public: -
trunk/WebCore/platform/graphics/GraphicsContext3D.h
r66055 r66781 452 452 #endif 453 453 #endif 454 void makeContextCurrent();454 void ensureContext(); 455 455 456 456 #if PLATFORM(MAC) || PLATFORM(CHROMIUM) -
trunk/WebCore/platform/graphics/GraphicsContext3DOpenGL.cpp
r66758 r66781 1 1 /* 2 * Copyright (C) 20 09Apple Inc. All rights reserved.2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 30 30 #include "GraphicsContext3D.h" 31 31 32 #import "BlockExceptions.h"33 34 32 #include "ArrayBuffer.h" 35 33 #include "ArrayBufferView.h" 36 #include "WebGLObject.h"37 34 #include "CanvasRenderingContext.h" 38 35 #include "Float32Array.h" … … 43 40 #include "NotImplemented.h" 44 41 #include "Uint8Array.h" 45 #include "WebGLLayer.h" 46 #include <CoreGraphics/CGBitmapContext.h> 42 #include "WebGLObject.h" 43 44 #if PLATFORM(MAC) 47 45 #include <OpenGL/CGLRenderers.h> 48 46 #include <OpenGL/gl.h> 47 #endif 48 49 49 #include <wtf/UnusedParam.h> 50 50 #include <wtf/text/CString.h> 51 51 52 52 namespace 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/supersampled107 // 2) 32 bit RGBA/32 bit depth/accelerated108 // 3) 32 bit RGBA/16 bit depth/accelerated109 // 4) closest to 32 bit RGBA/16 bit depth/software renderer110 //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 - fail129 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 - fail140 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 WebGLLayer150 BEGIN_BLOCK_OBJC_EXCEPTIONS151 m_webGLLayer.adoptNS([[WebGLLayer alloc] initWithGraphicsContext3D:this]);152 #ifndef NDEBUG153 [m_webGLLayer.get() setName:@"WebGL Layer"];154 #endif155 END_BLOCK_OBJC_EXCEPTIONS156 157 // create a texture to render into158 ::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 FBO167 ::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 FBO175 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 }231 53 232 54 void GraphicsContext3D::validateAttributes() … … 252 74 // correct behavior when premultipliedAlpha = false is requested. 253 75 m_attrs.premultipliedAlpha = true; 254 }255 256 void GraphicsContext3D::makeContextCurrent()257 {258 CGLSetCurrentContext(m_contextObj);259 76 } 260 77 … … 305 122 paintToCanvas(pixels.get(), m_currentWidth, m_currentHeight, 306 123 canvas->width(), canvas->height(), imageBuffer->context()->platformContext()); 307 }308 309 bool GraphicsContext3D::isGLES2Compliant() const310 {311 return false;312 }313 314 bool GraphicsContext3D::isGLES2NPOTStrict() const315 {316 return false;317 }318 319 bool GraphicsContext3D::isErrorGeneratedOnOutOfBoundsAccesses() const320 {321 return false;322 124 } 323 125 … … 453 255 } 454 256 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 257 void GraphicsContext3D::prepareTexture() 466 258 { 467 ensureContext( m_contextObj);259 ensureContext(); 468 260 if (m_attrs.antialias) { 469 261 ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO); … … 477 269 void GraphicsContext3D::activeTexture(unsigned long texture) 478 270 { 479 ensureContext( m_contextObj);271 ensureContext(); 480 272 ::glActiveTexture(texture); 481 273 } … … 485 277 ASSERT(program); 486 278 ASSERT(shader); 487 ensureContext( m_contextObj);279 ensureContext(); 488 280 ::glAttachShader((GLuint) program, (GLuint) shader); 489 281 } … … 492 284 { 493 285 ASSERT(program); 494 ensureContext( m_contextObj);286 ensureContext(); 495 287 ::glBindAttribLocation((GLuint) program, index, name.utf8().data()); 496 288 } … … 498 290 void GraphicsContext3D::bindBuffer(unsigned long target, Platform3DObject buffer) 499 291 { 500 ensureContext( m_contextObj);292 ensureContext(); 501 293 ::glBindBuffer(target, (GLuint) buffer); 502 294 } … … 505 297 void GraphicsContext3D::bindFramebuffer(unsigned long target, Platform3DObject buffer) 506 298 { 507 ensureContext( m_contextObj);299 ensureContext(); 508 300 GLuint fbo; 509 301 if (buffer) … … 519 311 void GraphicsContext3D::bindRenderbuffer(unsigned long target, Platform3DObject renderbuffer) 520 312 { 521 ensureContext( m_contextObj);313 ensureContext(); 522 314 ::glBindRenderbufferEXT(target, (GLuint) renderbuffer); 523 315 } … … 526 318 void GraphicsContext3D::bindTexture(unsigned long target, Platform3DObject texture) 527 319 { 528 ensureContext( m_contextObj);320 ensureContext(); 529 321 ::glBindTexture(target, (GLuint) texture); 530 322 } … … 532 324 void GraphicsContext3D::blendColor(double red, double green, double blue, double alpha) 533 325 { 534 ensureContext( m_contextObj);326 ensureContext(); 535 327 ::glBlendColor(static_cast<float>(red), static_cast<float>(green), static_cast<float>(blue), static_cast<float>(alpha)); 536 328 } 537 329 538 void GraphicsContext3D::blendEquation( unsigned long mode)539 { 540 ensureContext( m_contextObj);330 void GraphicsContext3D::blendEquation(unsigned long mode) 331 { 332 ensureContext(); 541 333 ::glBlendEquation(mode); 542 334 } … … 544 336 void GraphicsContext3D::blendEquationSeparate(unsigned long modeRGB, unsigned long modeAlpha) 545 337 { 546 ensureContext( m_contextObj);338 ensureContext(); 547 339 ::glBlendEquationSeparate(modeRGB, modeAlpha); 548 340 } … … 551 343 void GraphicsContext3D::blendFunc(unsigned long sfactor, unsigned long dfactor) 552 344 { 553 ensureContext( m_contextObj);345 ensureContext(); 554 346 ::glBlendFunc(sfactor, dfactor); 555 347 } … … 557 349 void GraphicsContext3D::blendFuncSeparate(unsigned long srcRGB, unsigned long dstRGB, unsigned long srcAlpha, unsigned long dstAlpha) 558 350 { 559 ensureContext( m_contextObj);351 ensureContext(); 560 352 ::glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); 561 353 } … … 563 355 void GraphicsContext3D::bufferData(unsigned long target, int size, unsigned long usage) 564 356 { 565 ensureContext( m_contextObj);357 ensureContext(); 566 358 ::glBufferData(target, size, 0, usage); 567 359 } … … 569 361 void GraphicsContext3D::bufferData(unsigned long target, int size, const void* data, unsigned long usage) 570 362 { 571 ensureContext( m_contextObj);363 ensureContext(); 572 364 ::glBufferData(target, size, data, usage); 573 365 } … … 575 367 void GraphicsContext3D::bufferSubData(unsigned long target, long offset, int size, const void* data) 576 368 { 577 ensureContext( m_contextObj);369 ensureContext(); 578 370 ::glBufferSubData(target, offset, size, data); 579 371 } … … 581 373 unsigned long GraphicsContext3D::checkFramebufferStatus(unsigned long target) 582 374 { 583 ensureContext( m_contextObj);375 ensureContext(); 584 376 return ::glCheckFramebufferStatusEXT(target); 585 377 } … … 587 379 void GraphicsContext3D::clearColor(double r, double g, double b, double a) 588 380 { 589 ensureContext( m_contextObj);381 ensureContext(); 590 382 ::glClearColor(static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a)); 591 383 } … … 593 385 void GraphicsContext3D::clear(unsigned long mask) 594 386 { 595 ensureContext( m_contextObj);387 ensureContext(); 596 388 ::glClear(mask); 597 389 } … … 599 391 void GraphicsContext3D::clearDepth(double depth) 600 392 { 601 ensureContext( m_contextObj);393 ensureContext(); 602 394 ::glClearDepth(depth); 603 395 } … … 605 397 void GraphicsContext3D::clearStencil(long s) 606 398 { 607 ensureContext( m_contextObj);399 ensureContext(); 608 400 ::glClearStencil(s); 609 401 } … … 611 403 void GraphicsContext3D::colorMask(bool red, bool green, bool blue, bool alpha) 612 404 { 613 ensureContext( m_contextObj);405 ensureContext(); 614 406 ::glColorMask(red, green, blue, alpha); 615 407 } … … 618 410 { 619 411 ASSERT(shader); 620 ensureContext( m_contextObj);412 ensureContext(); 621 413 622 414 int GLshaderType; … … 669 461 void GraphicsContext3D::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border) 670 462 { 671 ensureContext( m_contextObj);463 ensureContext(); 672 464 if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) { 673 465 ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO); … … 683 475 void GraphicsContext3D::copyTexSubImage2D(unsigned long target, long level, long xoffset, long yoffset, long x, long y, unsigned long width, unsigned long height) 684 476 { 685 ensureContext( m_contextObj);477 ensureContext(); 686 478 if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) { 687 479 ::glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_multisampleFBO); … … 697 489 void GraphicsContext3D::cullFace(unsigned long mode) 698 490 { 699 ensureContext( m_contextObj);491 ensureContext(); 700 492 ::glCullFace(mode); 701 493 } … … 703 495 void GraphicsContext3D::depthFunc(unsigned long func) 704 496 { 705 ensureContext( m_contextObj);497 ensureContext(); 706 498 ::glDepthFunc(func); 707 499 } … … 709 501 void GraphicsContext3D::depthMask(bool flag) 710 502 { 711 ensureContext( m_contextObj);503 ensureContext(); 712 504 ::glDepthMask(flag); 713 505 } … … 715 507 void GraphicsContext3D::depthRange(double zNear, double zFar) 716 508 { 717 ensureContext( m_contextObj);509 ensureContext(); 718 510 ::glDepthRange(zNear, zFar); 719 511 } … … 723 515 ASSERT(program); 724 516 ASSERT(shader); 725 ensureContext( m_contextObj);517 ensureContext(); 726 518 ::glDetachShader((GLuint) program, (GLuint) shader); 727 519 } … … 729 521 void GraphicsContext3D::disable(unsigned long cap) 730 522 { 731 ensureContext( m_contextObj);523 ensureContext(); 732 524 ::glDisable(cap); 733 525 } … … 735 527 void GraphicsContext3D::disableVertexAttribArray(unsigned long index) 736 528 { 737 ensureContext( m_contextObj);529 ensureContext(); 738 530 ::glDisableVertexAttribArray(index); 739 531 } … … 741 533 void GraphicsContext3D::drawArrays(unsigned long mode, long first, long count) 742 534 { 743 ensureContext( m_contextObj);535 ensureContext(); 744 536 ::glDrawArrays(mode, first, count); 745 537 } … … 747 539 void GraphicsContext3D::drawElements(unsigned long mode, unsigned long count, unsigned long type, long offset) 748 540 { 749 ensureContext( m_contextObj);541 ensureContext(); 750 542 ::glDrawElements(mode, count, type, reinterpret_cast<void*>(static_cast<intptr_t>(offset))); 751 543 } … … 753 545 void GraphicsContext3D::enable(unsigned long cap) 754 546 { 755 ensureContext( m_contextObj);547 ensureContext(); 756 548 ::glEnable(cap); 757 549 } … … 759 551 void GraphicsContext3D::enableVertexAttribArray(unsigned long index) 760 552 { 761 ensureContext( m_contextObj);553 ensureContext(); 762 554 ::glEnableVertexAttribArray(index); 763 555 } … … 765 557 void GraphicsContext3D::finish() 766 558 { 767 ensureContext( m_contextObj);559 ensureContext(); 768 560 ::glFinish(); 769 561 } … … 771 563 void GraphicsContext3D::flush() 772 564 { 773 ensureContext( m_contextObj);565 ensureContext(); 774 566 ::glFlush(); 775 567 } … … 777 569 void GraphicsContext3D::framebufferRenderbuffer(unsigned long target, unsigned long attachment, unsigned long renderbuffertarget, Platform3DObject buffer) 778 570 { 779 ensureContext( m_contextObj);571 ensureContext(); 780 572 GLuint renderbuffer = (GLuint) buffer; 781 573 if (attachment == DEPTH_STENCIL_ATTACHMENT) { … … 788 580 void GraphicsContext3D::framebufferTexture2D(unsigned long target, unsigned long attachment, unsigned long textarget, Platform3DObject texture, long level) 789 581 { 790 ensureContext( m_contextObj);582 ensureContext(); 791 583 ::glFramebufferTexture2DEXT(target, attachment, textarget, (GLuint) texture, level); 792 584 } … … 794 586 void GraphicsContext3D::frontFace(unsigned long mode) 795 587 { 796 ensureContext( m_contextObj);588 ensureContext(); 797 589 ::glFrontFace(mode); 798 590 } … … 800 592 void GraphicsContext3D::generateMipmap(unsigned long target) 801 593 { 802 ensureContext( m_contextObj);594 ensureContext(); 803 595 ::glGenerateMipmapEXT(target); 804 596 } … … 810 602 return false; 811 603 } 812 ensureContext( m_contextObj);604 ensureContext(); 813 605 GLint maxAttributeSize = 0; 814 606 ::glGetProgramiv(static_cast<GLuint>(program), GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeSize); … … 832 624 return false; 833 625 } 834 ensureContext( m_contextObj);626 ensureContext(); 835 627 GLint maxUniformSize = 0; 836 628 ::glGetProgramiv(static_cast<GLuint>(program), GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformSize); … … 854 646 return; 855 647 } 856 ensureContext( m_contextObj);648 ensureContext(); 857 649 ::glGetAttachedShaders(static_cast<GLuint>(program), maxCount, count, shaders); 858 650 } … … 862 654 if (!program) 863 655 return -1; 864 865 ensureContext( m_contextObj);656 657 ensureContext(); 866 658 return ::glGetAttribLocation((GLuint) program, name.utf8().data()); 867 659 } … … 881 673 } 882 674 883 ensureContext( m_contextObj);675 ensureContext(); 884 676 return ::glGetError(); 885 677 } … … 887 679 String GraphicsContext3D::getString(unsigned long name) 888 680 { 889 ensureContext( m_contextObj);681 ensureContext(); 890 682 return String((const char*) ::glGetString(name)); 891 683 } … … 893 685 void GraphicsContext3D::hint(unsigned long target, unsigned long mode) 894 686 { 895 ensureContext( m_contextObj);687 ensureContext(); 896 688 ::glHint(target, mode); 897 689 } … … 901 693 if (!buffer) 902 694 return false; 903 904 ensureContext( m_contextObj);695 696 ensureContext(); 905 697 return ::glIsBuffer((GLuint) buffer); 906 698 } … … 908 700 bool GraphicsContext3D::isEnabled(unsigned long cap) 909 701 { 910 ensureContext( m_contextObj);702 ensureContext(); 911 703 return ::glIsEnabled(cap); 912 704 } … … 916 708 if (!framebuffer) 917 709 return false; 918 919 ensureContext( m_contextObj);710 711 ensureContext(); 920 712 return ::glIsFramebufferEXT((GLuint) framebuffer); 921 713 } … … 925 717 if (!program) 926 718 return false; 927 928 ensureContext( m_contextObj);719 720 ensureContext(); 929 721 return ::glIsProgram((GLuint) program); 930 722 } … … 934 726 if (!renderbuffer) 935 727 return false; 936 937 ensureContext( m_contextObj);728 729 ensureContext(); 938 730 return ::glIsRenderbufferEXT((GLuint) renderbuffer); 939 731 } … … 943 735 if (!shader) 944 736 return false; 945 946 ensureContext( m_contextObj);737 738 ensureContext(); 947 739 return ::glIsShader((GLuint) shader); 948 740 } … … 952 744 if (!texture) 953 745 return false; 954 955 ensureContext( m_contextObj);746 747 ensureContext(); 956 748 return ::glIsTexture((GLuint) texture); 957 749 } … … 959 751 void GraphicsContext3D::lineWidth(double width) 960 752 { 961 ensureContext( m_contextObj);753 ensureContext(); 962 754 ::glLineWidth(static_cast<float>(width)); 963 755 } … … 966 758 { 967 759 ASSERT(program); 968 ensureContext( m_contextObj);760 ensureContext(); 969 761 ::glLinkProgram((GLuint) program); 970 762 } … … 972 764 void GraphicsContext3D::pixelStorei(unsigned long pname, long param) 973 765 { 974 ensureContext( m_contextObj);766 ensureContext(); 975 767 ::glPixelStorei(pname, param); 976 768 } … … 978 770 void GraphicsContext3D::polygonOffset(double factor, double units) 979 771 { 980 ensureContext( m_contextObj);772 ensureContext(); 981 773 ::glPolygonOffset(static_cast<float>(factor), static_cast<float>(units)); 982 774 } … … 986 778 // FIXME: remove the two glFlush calls when the driver bug is fixed, i.e., 987 779 // all previous rendering calls should be done before reading pixels. 988 ensureContext( m_contextObj);780 ensureContext(); 989 781 ::glFlush(); 990 782 if (m_attrs.antialias && m_boundFBO == m_multisampleFBO) { … … 1003 795 { 1004 796 // 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 797 } 1008 798 1009 799 void GraphicsContext3D::renderbufferStorage(unsigned long target, unsigned long internalformat, unsigned long width, unsigned long height) 1010 800 { 1011 ensureContext( m_contextObj);801 ensureContext(); 1012 802 switch (internalformat) { 1013 803 case DEPTH_STENCIL: … … 1030 820 void GraphicsContext3D::sampleCoverage(double value, bool invert) 1031 821 { 1032 ensureContext( m_contextObj);822 ensureContext(); 1033 823 ::glSampleCoverage(static_cast<float>(value), invert); 1034 824 } … … 1036 826 void GraphicsContext3D::scissor(long x, long y, unsigned long width, unsigned long height) 1037 827 { 1038 ensureContext( m_contextObj);828 ensureContext(); 1039 829 ::glScissor(x, y, width, height); 1040 830 } … … 1043 833 { 1044 834 ASSERT(shader); 1045 1046 ensureContext( m_contextObj);835 836 ensureContext(); 1047 837 1048 838 ShaderSourceEntry entry; … … 1055 845 void GraphicsContext3D::stencilFunc(unsigned long func, long ref, unsigned long mask) 1056 846 { 1057 ensureContext( m_contextObj);847 ensureContext(); 1058 848 ::glStencilFunc(func, ref, mask); 1059 849 } … … 1061 851 void GraphicsContext3D::stencilFuncSeparate(unsigned long face, unsigned long func, long ref, unsigned long mask) 1062 852 { 1063 ensureContext( m_contextObj);853 ensureContext(); 1064 854 ::glStencilFuncSeparate(face, func, ref, mask); 1065 855 } … … 1067 857 void GraphicsContext3D::stencilMask(unsigned long mask) 1068 858 { 1069 ensureContext( m_contextObj);859 ensureContext(); 1070 860 ::glStencilMask(mask); 1071 861 } … … 1073 863 void GraphicsContext3D::stencilMaskSeparate(unsigned long face, unsigned long mask) 1074 864 { 1075 ensureContext( m_contextObj);865 ensureContext(); 1076 866 ::glStencilMaskSeparate(face, mask); 1077 867 } … … 1079 869 void GraphicsContext3D::stencilOp(unsigned long fail, unsigned long zfail, unsigned long zpass) 1080 870 { 1081 ensureContext( m_contextObj);871 ensureContext(); 1082 872 ::glStencilOp(fail, zfail, zpass); 1083 873 } … … 1085 875 void GraphicsContext3D::stencilOpSeparate(unsigned long face, unsigned long fail, unsigned long zfail, unsigned long zpass) 1086 876 { 1087 ensureContext( m_contextObj);877 ensureContext(); 1088 878 ::glStencilOpSeparate(face, fail, zfail, zpass); 1089 879 } … … 1091 881 void GraphicsContext3D::texParameterf(unsigned target, unsigned pname, float value) 1092 882 { 1093 ensureContext( m_contextObj);883 ensureContext(); 1094 884 ::glTexParameterf(target, pname, static_cast<float>(value)); 1095 885 } … … 1097 887 void GraphicsContext3D::texParameteri(unsigned target, unsigned pname, int value) 1098 888 { 1099 ensureContext( m_contextObj);889 ensureContext(); 1100 890 ::glTexParameteri(target, pname, static_cast<float>(value)); 1101 891 } … … 1103 893 void GraphicsContext3D::uniform1f(long location, float v0) 1104 894 { 1105 ensureContext( m_contextObj);895 ensureContext(); 1106 896 ::glUniform1f(location, v0); 1107 897 } … … 1109 899 void GraphicsContext3D::uniform1fv(long location, float* array, int size) 1110 900 { 1111 ensureContext( m_contextObj);901 ensureContext(); 1112 902 ::glUniform1fv(location, size, array); 1113 903 } … … 1115 905 void GraphicsContext3D::uniform2f(long location, float v0, float v1) 1116 906 { 1117 ensureContext( m_contextObj);907 ensureContext(); 1118 908 ::glUniform2f(location, v0, v1); 1119 909 } … … 1122 912 { 1123 913 // FIXME: length needs to be a multiple of 2 1124 ensureContext( m_contextObj);914 ensureContext(); 1125 915 ::glUniform2fv(location, size, array); 1126 916 } … … 1128 918 void GraphicsContext3D::uniform3f(long location, float v0, float v1, float v2) 1129 919 { 1130 ensureContext( m_contextObj);920 ensureContext(); 1131 921 ::glUniform3f(location, v0, v1, v2); 1132 922 } … … 1135 925 { 1136 926 // FIXME: length needs to be a multiple of 3 1137 ensureContext( m_contextObj);927 ensureContext(); 1138 928 ::glUniform3fv(location, size, array); 1139 929 } … … 1141 931 void GraphicsContext3D::uniform4f(long location, float v0, float v1, float v2, float v3) 1142 932 { 1143 ensureContext( m_contextObj);933 ensureContext(); 1144 934 ::glUniform4f(location, v0, v1, v2, v3); 1145 935 } … … 1148 938 { 1149 939 // FIXME: length needs to be a multiple of 4 1150 ensureContext( m_contextObj);940 ensureContext(); 1151 941 ::glUniform4fv(location, size, array); 1152 942 } … … 1154 944 void GraphicsContext3D::uniform1i(long location, int v0) 1155 945 { 1156 ensureContext( m_contextObj);946 ensureContext(); 1157 947 ::glUniform1i(location, v0); 1158 948 } … … 1160 950 void GraphicsContext3D::uniform1iv(long location, int* array, int size) 1161 951 { 1162 ensureContext( m_contextObj);952 ensureContext(); 1163 953 ::glUniform1iv(location, size, array); 1164 954 } … … 1166 956 void GraphicsContext3D::uniform2i(long location, int v0, int v1) 1167 957 { 1168 ensureContext( m_contextObj);958 ensureContext(); 1169 959 ::glUniform2i(location, v0, v1); 1170 960 } … … 1173 963 { 1174 964 // FIXME: length needs to be a multiple of 2 1175 ensureContext( m_contextObj);965 ensureContext(); 1176 966 ::glUniform2iv(location, size, array); 1177 967 } … … 1179 969 void GraphicsContext3D::uniform3i(long location, int v0, int v1, int v2) 1180 970 { 1181 ensureContext( m_contextObj);971 ensureContext(); 1182 972 ::glUniform3i(location, v0, v1, v2); 1183 973 } … … 1186 976 { 1187 977 // FIXME: length needs to be a multiple of 3 1188 ensureContext( m_contextObj);978 ensureContext(); 1189 979 ::glUniform3iv(location, size, array); 1190 980 } … … 1192 982 void GraphicsContext3D::uniform4i(long location, int v0, int v1, int v2, int v3) 1193 983 { 1194 ensureContext( m_contextObj);984 ensureContext(); 1195 985 ::glUniform4i(location, v0, v1, v2, v3); 1196 986 } … … 1199 989 { 1200 990 // FIXME: length needs to be a multiple of 4 1201 ensureContext( m_contextObj);991 ensureContext(); 1202 992 ::glUniform4iv(location, size, array); 1203 993 } … … 1206 996 { 1207 997 // FIXME: length needs to be a multiple of 4 1208 ensureContext( m_contextObj);998 ensureContext(); 1209 999 ::glUniformMatrix2fv(location, size, transpose, array); 1210 1000 } … … 1213 1003 { 1214 1004 // FIXME: length needs to be a multiple of 9 1215 ensureContext( m_contextObj);1005 ensureContext(); 1216 1006 ::glUniformMatrix3fv(location, size, transpose, array); 1217 1007 } … … 1220 1010 { 1221 1011 // FIXME: length needs to be a multiple of 16 1222 ensureContext( m_contextObj);1012 ensureContext(); 1223 1013 ::glUniformMatrix4fv(location, size, transpose, array); 1224 1014 } … … 1226 1016 void GraphicsContext3D::useProgram(Platform3DObject program) 1227 1017 { 1228 ensureContext( m_contextObj);1018 ensureContext(); 1229 1019 ::glUseProgram((GLuint) program); 1230 1020 } … … 1233 1023 { 1234 1024 ASSERT(program); 1235 1236 ensureContext( m_contextObj);1025 1026 ensureContext(); 1237 1027 ::glValidateProgram((GLuint) program); 1238 1028 } … … 1240 1030 void GraphicsContext3D::vertexAttrib1f(unsigned long indx, float v0) 1241 1031 { 1242 ensureContext( m_contextObj);1032 ensureContext(); 1243 1033 ::glVertexAttrib1f(indx, v0); 1244 1034 } … … 1246 1036 void GraphicsContext3D::vertexAttrib1fv(unsigned long indx, float* array) 1247 1037 { 1248 ensureContext( m_contextObj);1038 ensureContext(); 1249 1039 ::glVertexAttrib1fv(indx, array); 1250 1040 } … … 1252 1042 void GraphicsContext3D::vertexAttrib2f(unsigned long indx, float v0, float v1) 1253 1043 { 1254 ensureContext( m_contextObj);1044 ensureContext(); 1255 1045 ::glVertexAttrib2f(indx, v0, v1); 1256 1046 } … … 1258 1048 void GraphicsContext3D::vertexAttrib2fv(unsigned long indx, float* array) 1259 1049 { 1260 ensureContext( m_contextObj);1050 ensureContext(); 1261 1051 ::glVertexAttrib2fv(indx, array); 1262 1052 } … … 1264 1054 void GraphicsContext3D::vertexAttrib3f(unsigned long indx, float v0, float v1, float v2) 1265 1055 { 1266 ensureContext( m_contextObj);1056 ensureContext(); 1267 1057 ::glVertexAttrib3f(indx, v0, v1, v2); 1268 1058 } … … 1270 1060 void GraphicsContext3D::vertexAttrib3fv(unsigned long indx, float* array) 1271 1061 { 1272 ensureContext( m_contextObj);1062 ensureContext(); 1273 1063 ::glVertexAttrib3fv(indx, array); 1274 1064 } … … 1276 1066 void GraphicsContext3D::vertexAttrib4f(unsigned long indx, float v0, float v1, float v2, float v3) 1277 1067 { 1278 ensureContext( m_contextObj);1068 ensureContext(); 1279 1069 ::glVertexAttrib4f(indx, v0, v1, v2, v3); 1280 1070 } … … 1282 1072 void GraphicsContext3D::vertexAttrib4fv(unsigned long indx, float* array) 1283 1073 { 1284 ensureContext( m_contextObj);1074 ensureContext(); 1285 1075 ::glVertexAttrib4fv(indx, array); 1286 1076 } … … 1288 1078 void GraphicsContext3D::vertexAttribPointer(unsigned long indx, int size, int type, bool normalized, unsigned long stride, unsigned long offset) 1289 1079 { 1290 ensureContext( m_contextObj);1080 ensureContext(); 1291 1081 ::glVertexAttribPointer(indx, size, type, normalized, stride, reinterpret_cast<void*>(static_cast<intptr_t>(offset))); 1292 1082 } … … 1294 1084 void GraphicsContext3D::viewport(long x, long y, unsigned long width, unsigned long height) 1295 1085 { 1296 ensureContext( m_contextObj);1086 ensureContext(); 1297 1087 ::glViewport(static_cast<GLint>(x), static_cast<GLint>(y), static_cast<GLsizei>(width), static_cast<GLsizei>(height)); 1298 1088 } … … 1300 1090 void GraphicsContext3D::getBooleanv(unsigned long pname, unsigned char* value) 1301 1091 { 1302 ensureContext( m_contextObj);1092 ensureContext(); 1303 1093 ::glGetBooleanv(pname, value); 1304 1094 } … … 1306 1096 void GraphicsContext3D::getBufferParameteriv(unsigned long target, unsigned long pname, int* value) 1307 1097 { 1308 ensureContext( m_contextObj);1098 ensureContext(); 1309 1099 ::glGetBufferParameteriv(target, pname, value); 1310 1100 } … … 1312 1102 void GraphicsContext3D::getFloatv(unsigned long pname, float* value) 1313 1103 { 1314 ensureContext( m_contextObj);1104 ensureContext(); 1315 1105 ::glGetFloatv(pname, value); 1316 1106 } … … 1318 1108 void GraphicsContext3D::getFramebufferAttachmentParameteriv(unsigned long target, unsigned long attachment, unsigned long pname, int* value) 1319 1109 { 1320 ensureContext( m_contextObj);1110 ensureContext(); 1321 1111 if (attachment == DEPTH_STENCIL_ATTACHMENT) 1322 1112 attachment = DEPTH_ATTACHMENT; // Or STENCIL_ATTACHMENT, either works. … … 1333 1123 // whereas GLES2 return the number of vectors (each vector has 4 components). 1334 1124 // Therefore, the value returned by desktop GL needs to be divided by 4. 1335 ensureContext( m_contextObj);1125 ensureContext(); 1336 1126 switch (pname) { 1337 1127 case IMPLEMENTATION_COLOR_READ_FORMAT: … … 1360 1150 void GraphicsContext3D::getProgramiv(Platform3DObject program, unsigned long pname, int* value) 1361 1151 { 1362 ensureContext( m_contextObj);1152 ensureContext(); 1363 1153 ::glGetProgramiv((GLuint) program, pname, value); 1364 1154 } … … 1367 1157 { 1368 1158 ASSERT(program); 1369 1370 ensureContext( m_contextObj);1159 1160 ensureContext(); 1371 1161 GLint length; 1372 1162 ::glGetProgramiv((GLuint) program, GL_INFO_LOG_LENGTH, &length); … … 1385 1175 void GraphicsContext3D::getRenderbufferParameteriv(unsigned long target, unsigned long pname, int* value) 1386 1176 { 1387 ensureContext( m_contextObj);1177 ensureContext(); 1388 1178 ::glGetRenderbufferParameterivEXT(target, pname, value); 1389 1179 } … … 1392 1182 { 1393 1183 ASSERT(shader); 1394 1395 ensureContext( m_contextObj);1396 1184 1185 ensureContext(); 1186 1397 1187 HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader); 1398 1188 1399 1189 switch (pname) { 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 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); 1431 1221 } 1432 1222 } … … 1436 1226 ASSERT(shader); 1437 1227 1438 ensureContext( m_contextObj);1228 ensureContext(); 1439 1229 GLint length; 1440 1230 ::glGetShaderiv((GLuint) shader, GL_INFO_LOG_LENGTH, &length); … … 1448 1238 1449 1239 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; 1467 1256 } 1468 1257 … … 1471 1260 ASSERT(shader); 1472 1261 1473 ensureContext( m_contextObj);1262 ensureContext(); 1474 1263 1475 1264 HashMap<Platform3DObject, ShaderSourceEntry>::iterator result = m_shaderSourceMap.find(shader); … … 1484 1273 void GraphicsContext3D::getTexParameterfv(unsigned long target, unsigned long pname, float* value) 1485 1274 { 1486 ensureContext( m_contextObj);1275 ensureContext(); 1487 1276 ::glGetTexParameterfv(target, pname, value); 1488 1277 } … … 1490 1279 void GraphicsContext3D::getTexParameteriv(unsigned long target, unsigned long pname, int* value) 1491 1280 { 1492 ensureContext( m_contextObj);1281 ensureContext(); 1493 1282 ::glGetTexParameteriv(target, pname, value); 1494 1283 } … … 1496 1285 void GraphicsContext3D::getUniformfv(Platform3DObject program, long location, float* value) 1497 1286 { 1498 ensureContext( m_contextObj);1287 ensureContext(); 1499 1288 ::glGetUniformfv((GLuint) program, location, value); 1500 1289 } … … 1502 1291 void GraphicsContext3D::getUniformiv(Platform3DObject program, long location, int* value) 1503 1292 { 1504 ensureContext( m_contextObj);1293 ensureContext(); 1505 1294 ::glGetUniformiv((GLuint) program, location, value); 1506 1295 } … … 1509 1298 { 1510 1299 ASSERT(program); 1511 1512 ensureContext( m_contextObj);1300 1301 ensureContext(); 1513 1302 return ::glGetUniformLocation((GLuint) program, name.utf8().data()); 1514 1303 } … … 1516 1305 void GraphicsContext3D::getVertexAttribfv(unsigned long index, unsigned long pname, float* value) 1517 1306 { 1518 ensureContext( m_contextObj);1307 ensureContext(); 1519 1308 ::glGetVertexAttribfv(index, pname, value); 1520 1309 } … … 1522 1311 void GraphicsContext3D::getVertexAttribiv(unsigned long index, unsigned long pname, int* value) 1523 1312 { 1524 ensureContext( m_contextObj);1313 ensureContext(); 1525 1314 ::glGetVertexAttribiv(index, pname, value); 1526 1315 } … … 1528 1317 long GraphicsContext3D::getVertexAttribOffset(unsigned long index, unsigned long pname) 1529 1318 { 1530 ensureContext( m_contextObj);1531 1319 ensureContext(); 1320 1532 1321 void* pointer; 1533 1322 ::glGetVertexAttribPointerv(index, pname, &pointer); … … 1537 1326 int GraphicsContext3D::texImage2D(unsigned target, unsigned level, unsigned internalformat, unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels) 1538 1327 { 1539 ensureContext( m_contextObj);1328 ensureContext(); 1540 1329 1541 1330 ::glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels); … … 1545 1334 int GraphicsContext3D::texSubImage2D(unsigned target, unsigned level, unsigned xoff, unsigned yoff, unsigned width, unsigned height, unsigned format, unsigned type, void* pixels) 1546 1335 { 1547 ensureContext( m_contextObj);1336 ensureContext(); 1548 1337 1549 1338 // FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size … … 1554 1343 unsigned GraphicsContext3D::createBuffer() 1555 1344 { 1556 ensureContext( m_contextObj);1345 ensureContext(); 1557 1346 GLuint o; 1558 1347 glGenBuffers(1, &o); … … 1562 1351 unsigned GraphicsContext3D::createFramebuffer() 1563 1352 { 1564 ensureContext( m_contextObj);1353 ensureContext(); 1565 1354 GLuint o; 1566 1355 glGenFramebuffersEXT(1, &o); … … 1570 1359 unsigned GraphicsContext3D::createProgram() 1571 1360 { 1572 ensureContext( m_contextObj);1361 ensureContext(); 1573 1362 return glCreateProgram(); 1574 1363 } … … 1576 1365 unsigned GraphicsContext3D::createRenderbuffer() 1577 1366 { 1578 ensureContext( m_contextObj);1367 ensureContext(); 1579 1368 GLuint o; 1580 1369 glGenRenderbuffersEXT(1, &o); … … 1584 1373 unsigned GraphicsContext3D::createShader(unsigned long type) 1585 1374 { 1586 ensureContext( m_contextObj);1375 ensureContext(); 1587 1376 return glCreateShader((type == FRAGMENT_SHADER) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER); 1588 1377 } … … 1590 1379 unsigned GraphicsContext3D::createTexture() 1591 1380 { 1592 ensureContext( m_contextObj);1381 ensureContext(); 1593 1382 GLuint o; 1594 1383 glGenTextures(1, &o); … … 1598 1387 void GraphicsContext3D::deleteBuffer(unsigned buffer) 1599 1388 { 1600 ensureContext( m_contextObj);1389 ensureContext(); 1601 1390 glDeleteBuffers(1, &buffer); 1602 1391 } … … 1604 1393 void GraphicsContext3D::deleteFramebuffer(unsigned framebuffer) 1605 1394 { 1606 ensureContext( m_contextObj);1395 ensureContext(); 1607 1396 glDeleteFramebuffersEXT(1, &framebuffer); 1608 1397 } … … 1610 1399 void GraphicsContext3D::deleteProgram(unsigned program) 1611 1400 { 1612 ensureContext( m_contextObj);1401 ensureContext(); 1613 1402 glDeleteProgram(program); 1614 1403 } … … 1616 1405 void GraphicsContext3D::deleteRenderbuffer(unsigned renderbuffer) 1617 1406 { 1618 ensureContext( m_contextObj);1407 ensureContext(); 1619 1408 glDeleteRenderbuffersEXT(1, &renderbuffer); 1620 1409 } … … 1622 1411 void GraphicsContext3D::deleteShader(unsigned shader) 1623 1412 { 1624 ensureContext( m_contextObj);1413 ensureContext(); 1625 1414 glDeleteShader(shader); 1626 1415 } … … 1628 1417 void GraphicsContext3D::deleteTexture(unsigned texture) 1629 1418 { 1630 ensureContext( m_contextObj);1419 ensureContext(); 1631 1420 glDeleteTextures(1, &texture); 1632 1421 } … … 1635 1424 { 1636 1425 switch (type) { 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 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; 1653 1442 } 1654 1443 } -
trunk/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm
r66675 r66781 32 32 #import "BlockExceptions.h" 33 33 34 #include "ANGLE/ShaderLang.h" 34 35 #include "ArrayBuffer.h" 35 36 #include "ArrayBufferView.h" 36 #include "WebGLObject.h"37 37 #include "CanvasRenderingContext.h" 38 #include <CoreGraphics/CGBitmapContext.h> 38 39 #include "Float32Array.h" 39 40 #include "GraphicsContext.h" … … 42 43 #include "Int32Array.h" 43 44 #include "NotImplemented.h" 45 #include <OpenGL/CGLRenderers.h> 46 #include <OpenGL/gl.h> 44 47 #include "Uint8Array.h" 45 48 #include "WebGLLayer.h" 46 #include <CoreGraphics/CGBitmapContext.h> 47 #include <OpenGL/CGLRenderers.h> 48 #include <OpenGL/gl.h> 49 #include "WebGLObject.h" 49 50 #include <wtf/UnusedParam.h> 50 51 #include <wtf/text/CString.h> … … 230 231 } 231 232 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) 233 void GraphicsContext3D::ensureContext() 234 { 235 if (!m_contextObj) 271 236 return; 272 237 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); 307 241 } 308 242 … … 321 255 return false; 322 256 } 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 1660 258 1661 259 }
Note: See TracChangeset
for help on using the changeset viewer.