Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef WebGLProgram_h | 26 #ifndef WebGLProgram_h |
| 27 #define WebGLProgram_h | 27 #define WebGLProgram_h |
| 28 | 28 |
| 29 #include "bindings/v8/ScriptWrappable.h" | 29 #include "bindings/v8/ScriptWrappable.h" |
| 30 #include "core/html/canvas/WebGLSharedObject.h" | 30 #include "core/html/canvas/WebGLSharedObject.h" |
| 31 #include "core/html/canvas/WebGLShader.h" | 31 #include "core/html/canvas/WebGLShader.h" |
| 32 #include "wtf/HashMap.h" | |
| 32 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
| 33 #include "wtf/RefCounted.h" | 34 #include "wtf/RefCounted.h" |
| 34 #include "wtf/Vector.h" | 35 #include "wtf/Vector.h" |
| 35 | 36 |
| 36 namespace WebCore { | 37 namespace WebCore { |
| 37 | 38 |
| 38 class WebGLProgram : public WebGLSharedObject, public ScriptWrappable { | 39 class WebGLProgram : public WebGLSharedObject, public ScriptWrappable { |
| 39 public: | 40 public: |
| 41 struct SamplerInfo { | |
| 42 SamplerInfo(GC3Denum type, GC3Dint nextLocation) | |
| 43 : type(type) | |
| 44 , unit(0) | |
| 45 , nextLocation(nextLocation) | |
| 46 { | |
| 47 } | |
| 48 SamplerInfo() | |
| 49 : type(0) | |
| 50 , unit(-1) | |
| 51 , nextLocation(-1) | |
| 52 { | |
| 53 } | |
| 54 GC3Denum type; | |
| 55 GC3Dint unit; | |
| 56 GC3Dint nextLocation; | |
| 57 }; | |
| 58 typedef HashMap<GC3Dint, SamplerInfo> SamplerTextureUnitMap; | |
| 59 | |
| 40 virtual ~WebGLProgram(); | 60 virtual ~WebGLProgram(); |
| 41 | 61 |
| 42 static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*); | 62 static PassRefPtr<WebGLProgram> create(WebGLRenderingContext*); |
| 43 | 63 |
| 44 unsigned numActiveAttribLocations(); | 64 unsigned numActiveAttribLocations(WebGLRenderingContext*); |
| 45 GC3Dint getActiveAttribLocation(GC3Duint index); | 65 GC3Dint getActiveAttribLocation(WebGLRenderingContext*, GC3Duint index); |
| 46 | 66 |
| 47 bool isUsingVertexAttrib0(); | 67 bool isUsingVertexAttrib0(WebGLRenderingContext*); |
| 48 | 68 |
| 49 bool getLinkStatus(); | 69 bool getLinkStatus(WebGLRenderingContext*); |
| 50 void setLinkStatus(bool); | 70 void setLinkStatus(WebGLRenderingContext*, bool); |
| 51 | 71 |
| 52 unsigned getLinkCount() const { return m_linkCount; } | 72 unsigned getLinkCount() const { return m_linkCount; } |
| 53 | 73 |
| 54 // This is to be called everytime after the program is successfully linked. | 74 // This is to be called everytime after the program is successfully linked. |
| 55 // We don't deal with integer overflow here, assuming in reality a program | 75 // We don't deal with integer overflow here, assuming in reality a program |
| 56 // will never be linked so many times. | 76 // will never be linked so many times. |
| 57 // Also, we invalidate the cached program info. | 77 // Also, we invalidate the cached program info. |
| 58 void increaseLinkCount(); | 78 void increaseLinkCount(); |
| 59 | 79 |
| 60 WebGLShader* getAttachedShader(GC3Denum); | 80 WebGLShader* getAttachedShader(GC3Denum); |
| 61 bool attachShader(WebGLShader*); | 81 bool attachShader(WebGLShader*); |
| 62 bool detachShader(WebGLShader*); | 82 bool detachShader(WebGLShader*); |
| 63 | 83 |
| 84 void setSampler(WebGLRenderingContext*, GC3Dint, GC3Dsizei, const GC3Dint*); | |
|
Ken Russell (switch to Gerrit)
2013/06/19 03:51:24
Would a more descriptive name like "conditionallyS
greggman
2013/06/21 19:54:21
Done.
| |
| 85 const SamplerTextureUnitMap& samplerLocationTextureUnitMap() const | |
| 86 { | |
| 87 return m_samplerLocationToTextureUnit; | |
| 88 } | |
| 89 | |
| 64 protected: | 90 protected: |
| 65 WebGLProgram(WebGLRenderingContext*); | 91 WebGLProgram(WebGLRenderingContext*); |
| 66 | 92 |
| 67 virtual void deleteObjectImpl(GraphicsContext3D*, Platform3DObject); | 93 virtual void deleteObjectImpl(GraphicsContext3D*, Platform3DObject); |
| 68 | 94 |
| 69 private: | 95 private: |
| 70 virtual bool isProgram() const { return true; } | 96 virtual bool isProgram() const { return true; } |
| 97 virtual const char* typeName() const { return "WebGLProgram"; } | |
| 71 | 98 |
| 72 void cacheActiveAttribLocations(GraphicsContext3D*); | 99 void cacheActiveAttribLocations(GraphicsContext3D*); |
| 73 void cacheInfoIfNeeded(); | 100 void cacheSamplerLocations(GraphicsContext3D*); |
| 101 void cacheInfoIfNeeded(WebGLRenderingContext*); | |
| 74 | 102 |
| 75 Vector<GC3Dint> m_activeAttribLocations; | 103 Vector<GC3Dint> m_activeAttribLocations; |
| 104 SamplerTextureUnitMap m_samplerLocationToTextureUnit; | |
| 76 | 105 |
| 77 GC3Dint m_linkStatus; | 106 GC3Dint m_linkStatus; |
| 78 | 107 |
| 79 // This is used to track whether a WebGLUniformLocation belongs to this | 108 // This is used to track whether a WebGLUniformLocation belongs to this |
| 80 // program or not. | 109 // program or not. |
| 81 unsigned m_linkCount; | 110 unsigned m_linkCount; |
| 82 | 111 |
| 83 RefPtr<WebGLShader> m_vertexShader; | 112 RefPtr<WebGLShader> m_vertexShader; |
| 84 RefPtr<WebGLShader> m_fragmentShader; | 113 RefPtr<WebGLShader> m_fragmentShader; |
| 85 | 114 |
| 86 bool m_infoValid; | 115 bool m_infoValid; |
| 87 }; | 116 }; |
| 88 | 117 |
| 89 } // namespace WebCore | 118 } // namespace WebCore |
| 90 | 119 |
| 91 #endif // WebGLProgram_h | 120 #endif // WebGLProgram_h |
| OLD | NEW |