1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGL2Context.h"
9 #include "WebGLFramebuffer.h"
13 bool WebGL2Context::ValidateClearBuffer(const GLenum buffer
,
14 const GLint drawBuffer
,
15 const webgl::AttribBaseType funcType
) {
19 maxDrawBuffer
= Limits().maxColorDrawBuffers
- 1;
23 case LOCAL_GL_STENCIL
:
27 case LOCAL_GL_DEPTH_STENCIL
:
32 ErrorInvalidEnumInfo("buffer", buffer
);
36 if (drawBuffer
< 0 || drawBuffer
> maxDrawBuffer
) {
38 "Invalid drawbuffer %d. This buffer only supports"
39 " `drawbuffer` values between 0 and %u.",
40 drawBuffer
, maxDrawBuffer
);
46 if (!BindCurFBForDraw()) return false;
48 const auto& fb
= mBoundDrawFramebuffer
;
50 if (!fb
->ValidateClearBufferType(buffer
, drawBuffer
, funcType
))
52 } else if (buffer
== LOCAL_GL_COLOR
) {
53 if (drawBuffer
!= 0) return true;
55 if (mDefaultFB_DrawBuffer0
== LOCAL_GL_NONE
) return true;
57 if (funcType
!= webgl::AttribBaseType::Float
) {
58 ErrorInvalidOperation(
59 "For default framebuffer, COLOR is always of type"
70 void WebGL2Context::ClearBufferTv(GLenum buffer
, GLint drawBuffer
,
71 const webgl::TypedQuad
& data
) {
72 const FuncScope
funcScope(*this, "clearBufferu?[fi]v");
73 if (IsContextLost()) return;
76 case webgl::AttribBaseType::Boolean
:
80 case webgl::AttribBaseType::Float
:
81 if (buffer
!= LOCAL_GL_COLOR
&& buffer
!= LOCAL_GL_DEPTH
) {
82 ErrorInvalidEnum("`buffer` must be COLOR or DEPTH.");
87 case webgl::AttribBaseType::Int
:
88 if (buffer
!= LOCAL_GL_COLOR
&& buffer
!= LOCAL_GL_STENCIL
) {
89 ErrorInvalidEnum("`buffer` must be COLOR or STENCIL.");
94 case webgl::AttribBaseType::Uint
:
95 if (buffer
!= LOCAL_GL_COLOR
) {
96 ErrorInvalidEnum("`buffer` must be COLOR.");
102 if (!ValidateClearBuffer(buffer
, drawBuffer
, data
.type
)) {
106 if (!mBoundDrawFramebuffer
&& buffer
== LOCAL_GL_DEPTH
&& mNeedsFakeNoDepth
) {
109 if (!mBoundDrawFramebuffer
&& buffer
== LOCAL_GL_STENCIL
&&
110 mNeedsFakeNoStencil
) {
114 ScopedDrawCallWrapper
wrapper(*this);
116 case webgl::AttribBaseType::Boolean
:
120 case webgl::AttribBaseType::Float
:
121 gl
->fClearBufferfv(buffer
, drawBuffer
,
122 reinterpret_cast<const float*>(data
.data
.data()));
125 case webgl::AttribBaseType::Int
:
126 gl
->fClearBufferiv(buffer
, drawBuffer
,
127 reinterpret_cast<const int32_t*>(data
.data
.data()));
130 case webgl::AttribBaseType::Uint
:
131 gl
->fClearBufferuiv(buffer
, drawBuffer
,
132 reinterpret_cast<const uint32_t*>(data
.data
.data()));
139 void WebGL2Context::ClearBufferfi(GLenum buffer
, GLint drawBuffer
,
140 GLfloat depth
, GLint stencil
) {
141 const FuncScope
funcScope(*this, "clearBufferfi");
142 if (IsContextLost()) return;
144 if (buffer
!= LOCAL_GL_DEPTH_STENCIL
)
145 return ErrorInvalidEnum("`buffer` must be DEPTH_STENCIL.");
147 const auto ignored
= webgl::AttribBaseType::Float
;
148 if (!ValidateClearBuffer(buffer
, drawBuffer
, ignored
)) return;
150 auto driverDepth
= depth
;
151 auto driverStencil
= stencil
;
152 if (!mBoundDrawFramebuffer
) {
153 if (mNeedsFakeNoDepth
) {
155 } else if (mNeedsFakeNoStencil
) {
160 ScopedDrawCallWrapper
wrapper(*this);
161 gl
->fClearBufferfi(buffer
, drawBuffer
, driverDepth
, driverStencil
);
164 } // namespace mozilla