1 // Copyright 2015 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_TRANSFORM_FEEDBACK_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_TRANSFORM_FEEDBACK_H_ 7 8 #include "base/memory/scoped_refptr.h" 9 #include "third_party/blink/renderer/modules/webgl/webgl_context_object.h" 10 #include "third_party/blink/renderer/modules/webgl/webgl_program.h" 11 12 namespace blink { 13 14 class WebGL2RenderingContextBase; 15 class WebGLBuffer; 16 17 class WebGLTransformFeedback : public WebGLContextObject { 18 DEFINE_WRAPPERTYPEINFO(); 19 20 public: 21 enum TFType { 22 TFTypeDefault, 23 TFTypeUser, 24 }; 25 26 explicit WebGLTransformFeedback(WebGL2RenderingContextBase*, TFType); 27 ~WebGLTransformFeedback() override; 28 Object()29 GLuint Object() const { return object_; } 30 IsDefaultObject()31 bool IsDefaultObject() const { return type_ == TFTypeDefault; } 32 GetTarget()33 GLenum GetTarget() const { return target_; } 34 void SetTarget(GLenum); 35 HasEverBeenBound()36 bool HasEverBeenBound() const { return object_ && target_; } 37 GetProgram()38 WebGLProgram* GetProgram() const { return program_; } 39 void SetProgram(WebGLProgram*); 40 41 // These are the indexed bind points for transform feedback buffers. 42 // Returns false if index is out of range and the caller should 43 // synthesize a GL error. 44 bool SetBoundIndexedTransformFeedbackBuffer(GLuint index, WebGLBuffer*); 45 bool GetBoundIndexedTransformFeedbackBuffer(GLuint index, 46 WebGLBuffer** outBuffer) const; 47 bool HasEnoughBuffers(GLuint num_required) const; 48 49 bool UsesBuffer(WebGLBuffer*); 50 void UnbindBuffer(WebGLBuffer*); 51 52 void Trace(Visitor*) const override; 53 active()54 bool active() const { return active_; } paused()55 bool paused() const { return paused_; } 56 const HeapVector<Member<WebGLBuffer>>& bound_indexed_transform_feedback_buffers()57 bound_indexed_transform_feedback_buffers() const { 58 return bound_indexed_transform_feedback_buffers_; 59 } 60 SetActive(bool active)61 void SetActive(bool active) { 62 active_ = active; 63 DCHECK(active_ || !paused_); 64 } SetPaused(bool paused)65 void SetPaused(bool paused) { 66 paused_ = paused; 67 DCHECK(active_ || !paused_); 68 } 69 70 bool ValidateProgramForResume(WebGLProgram*) const; 71 72 private: 73 void DispatchDetached(gpu::gles2::GLES2Interface*); HasObject()74 bool HasObject() const override { return object_ != 0; } 75 void DeleteObjectImpl(gpu::gles2::GLES2Interface*) override; 76 77 GLuint object_; 78 79 TFType type_; 80 GLenum target_; 81 82 HeapVector<Member<WebGLBuffer>> bound_indexed_transform_feedback_buffers_; 83 84 Member<WebGLProgram> program_; 85 unsigned program_link_count_; 86 bool active_; 87 bool paused_; 88 }; 89 90 } // namespace blink 91 92 #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_TRANSFORM_FEEDBACK_H_ 93