mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 01:17:36 +00:00
LibWeb/WebGL: Implement error handling and getError()
This commit is contained in:
parent
528c7bea03
commit
a6617e1096
3 changed files with 39 additions and 0 deletions
|
@ -21,6 +21,13 @@ WebGLRenderingContextBase::WebGLRenderingContextBase(HTML::HTMLCanvasElement& ca
|
|||
|
||||
WebGLRenderingContextBase::~WebGLRenderingContextBase() = default;
|
||||
|
||||
#define RETURN_WITH_WEBGL_ERROR_IF(condition, error) \
|
||||
if (condition) { \
|
||||
dbgln_if(WEBGL_CONTEXT_DEBUG, "{}(): error {:#x}", __func__, error); \
|
||||
set_error(error); \
|
||||
return; \
|
||||
}
|
||||
|
||||
void WebGLRenderingContextBase::present()
|
||||
{
|
||||
if (!m_should_present)
|
||||
|
@ -71,6 +78,15 @@ void WebGLRenderingContextBase::needs_to_present()
|
|||
m_canvas_element->layout_node()->set_needs_display();
|
||||
}
|
||||
|
||||
void WebGLRenderingContextBase::set_error(GLenum error)
|
||||
{
|
||||
auto context_error = m_context->gl_get_error();
|
||||
if (context_error != GL_NO_ERROR)
|
||||
m_error = context_error;
|
||||
else
|
||||
m_error = error;
|
||||
}
|
||||
|
||||
bool WebGLRenderingContextBase::is_context_lost() const
|
||||
{
|
||||
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::is_context_lost()");
|
||||
|
@ -210,6 +226,22 @@ void WebGLRenderingContextBase::front_face(GLenum mode)
|
|||
m_context->gl_front_face(mode);
|
||||
}
|
||||
|
||||
GLenum WebGLRenderingContextBase::get_error()
|
||||
{
|
||||
dbgln_if(WEBGL_CONTEXT_DEBUG, "WebGLRenderingContextBase::get_error()");
|
||||
|
||||
// "If the context's webgl context lost flag is set, returns CONTEXT_LOST_WEBGL the first time this method is called. Afterward, returns NO_ERROR until the context has been restored."
|
||||
// FIXME: The plan here is to make the context lost handler unconditionally set m_error to CONTEXT_LOST_WEBGL, which we currently do not have.
|
||||
// The idea for the unconditional set is that any potentially error generating functions will not execute when the context is lost.
|
||||
if (m_error != GL_NO_ERROR || m_context_lost) {
|
||||
auto last_error = m_error;
|
||||
m_error = GL_NO_ERROR;
|
||||
return last_error;
|
||||
}
|
||||
|
||||
return m_context->gl_get_error();
|
||||
}
|
||||
|
||||
void WebGLRenderingContextBase::polygon_offset(GLfloat factor, GLfloat units)
|
||||
{
|
||||
if (m_context_lost)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue