mirror of
https://github.com/zebrajr/ladybird.git
synced 2025-12-06 00:19:53 +01:00
LibWeb/WebGL2: Implement most of the query APIs
This commit is contained in:
parent
2b941731a7
commit
5c1bf5c3f6
|
|
@ -1209,6 +1209,7 @@ class WebGLContextEvent;
|
|||
class WebGLFramebuffer;
|
||||
class WebGLObject;
|
||||
class WebGLProgram;
|
||||
class WebGLQuery;
|
||||
class WebGLRenderbuffer;
|
||||
class WebGLRenderingContext;
|
||||
class WebGLSampler;
|
||||
|
|
|
|||
|
|
@ -377,13 +377,13 @@ interface mixin WebGL2RenderingContextBase {
|
|||
undefined clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil);
|
||||
|
||||
// Query Objects
|
||||
[FIXME] WebGLQuery createQuery();
|
||||
[FIXME] undefined deleteQuery(WebGLQuery? query);
|
||||
WebGLQuery createQuery();
|
||||
undefined deleteQuery(WebGLQuery? query);
|
||||
[FIXME] GLboolean isQuery(WebGLQuery? query); // [WebGLHandlesContextLoss]
|
||||
[FIXME] undefined beginQuery(GLenum target, WebGLQuery query);
|
||||
[FIXME] undefined endQuery(GLenum target);
|
||||
undefined beginQuery(GLenum target, WebGLQuery query);
|
||||
undefined endQuery(GLenum target);
|
||||
[FIXME] WebGLQuery? getQuery(GLenum target, GLenum pname);
|
||||
[FIXME] any getQueryParameter(WebGLQuery query, GLenum pname);
|
||||
any getQueryParameter(WebGLQuery query, GLenum pname);
|
||||
|
||||
// Sampler Objects
|
||||
WebGLSampler createSampler();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES 1
|
||||
|
||||
#include <GLES3/gl3.h>
|
||||
extern "C" {
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
|
@ -22,6 +23,7 @@ extern "C" {
|
|||
#include <LibWeb/WebGL/WebGLBuffer.h>
|
||||
#include <LibWeb/WebGL/WebGLFramebuffer.h>
|
||||
#include <LibWeb/WebGL/WebGLProgram.h>
|
||||
#include <LibWeb/WebGL/WebGLQuery.h>
|
||||
#include <LibWeb/WebGL/WebGLRenderbuffer.h>
|
||||
#include <LibWeb/WebGL/WebGLSampler.h>
|
||||
#include <LibWeb/WebGL/WebGLShader.h>
|
||||
|
|
@ -519,6 +521,82 @@ void WebGL2RenderingContextImpl::clear_bufferfi(WebIDL::UnsignedLong buffer, Web
|
|||
glClearBufferfi(buffer, drawbuffer, depth, stencil);
|
||||
}
|
||||
|
||||
GC::Root<WebGLQuery> WebGL2RenderingContextImpl::create_query()
|
||||
{
|
||||
m_context->make_current();
|
||||
|
||||
GLuint handle = 0;
|
||||
glGenQueries(1, &handle);
|
||||
return WebGLQuery::create(m_realm, *this, handle);
|
||||
}
|
||||
|
||||
void WebGL2RenderingContextImpl::delete_query(GC::Root<WebGLQuery> query)
|
||||
{
|
||||
m_context->make_current();
|
||||
|
||||
GLuint query_handle = 0;
|
||||
if (query) {
|
||||
auto handle_or_error = query->handle(this);
|
||||
if (handle_or_error.is_error()) {
|
||||
set_error(GL_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
query_handle = handle_or_error.release_value();
|
||||
}
|
||||
|
||||
glDeleteQueries(1, &query_handle);
|
||||
}
|
||||
|
||||
void WebGL2RenderingContextImpl::begin_query(WebIDL::UnsignedLong target, GC::Root<WebGLQuery> query)
|
||||
{
|
||||
m_context->make_current();
|
||||
|
||||
GLuint query_handle = 0;
|
||||
if (query) {
|
||||
auto handle_or_error = query->handle(this);
|
||||
if (handle_or_error.is_error()) {
|
||||
set_error(GL_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
query_handle = handle_or_error.release_value();
|
||||
}
|
||||
|
||||
glBeginQuery(target, query_handle);
|
||||
}
|
||||
|
||||
void WebGL2RenderingContextImpl::end_query(WebIDL::UnsignedLong target)
|
||||
{
|
||||
m_context->make_current();
|
||||
glEndQuery(target);
|
||||
}
|
||||
|
||||
JS::Value WebGL2RenderingContextImpl::get_query_parameter(GC::Root<WebGLQuery> query, WebIDL::UnsignedLong pname)
|
||||
{
|
||||
m_context->make_current();
|
||||
|
||||
GLuint query_handle = 0;
|
||||
if (query) {
|
||||
auto handle_or_error = query->handle(this);
|
||||
if (handle_or_error.is_error()) {
|
||||
set_error(GL_INVALID_OPERATION);
|
||||
return JS::js_null();
|
||||
}
|
||||
query_handle = handle_or_error.release_value();
|
||||
}
|
||||
|
||||
GLuint result { 0 };
|
||||
glGetQueryObjectuivRobustANGLE(query_handle, pname, 1, nullptr, &result);
|
||||
|
||||
switch (pname) {
|
||||
case GL_QUERY_RESULT:
|
||||
return JS::Value(result);
|
||||
case GL_QUERY_RESULT_AVAILABLE:
|
||||
return JS::Value(result == GL_TRUE);
|
||||
default:
|
||||
return JS::js_null();
|
||||
}
|
||||
}
|
||||
|
||||
GC::Root<WebGLSampler> WebGL2RenderingContextImpl::create_sampler()
|
||||
{
|
||||
m_context->make_current();
|
||||
|
|
|
|||
|
|
@ -67,6 +67,11 @@ public:
|
|||
void clear_bufferiv(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, Int32List values, WebIDL::UnsignedLongLong src_offset);
|
||||
void clear_bufferuiv(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, Uint32List values, WebIDL::UnsignedLongLong src_offset);
|
||||
void clear_bufferfi(WebIDL::UnsignedLong buffer, WebIDL::Long drawbuffer, float depth, WebIDL::Long stencil);
|
||||
GC::Root<WebGLQuery> create_query();
|
||||
void delete_query(GC::Root<WebGLQuery> query);
|
||||
void begin_query(WebIDL::UnsignedLong target, GC::Root<WebGLQuery> query);
|
||||
void end_query(WebIDL::UnsignedLong target);
|
||||
JS::Value get_query_parameter(GC::Root<WebGLQuery> query, WebIDL::UnsignedLong pname);
|
||||
GC::Root<WebGLSampler> create_sampler();
|
||||
void delete_sampler(GC::Root<WebGLSampler> sampler);
|
||||
void bind_sampler(WebIDL::UnsignedLong unit, GC::Root<WebGLSampler> sampler);
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ static bool is_platform_object(Type const& type)
|
|||
"WebGLFramebuffer"sv,
|
||||
"WebGLObject"sv,
|
||||
"WebGLProgram"sv,
|
||||
"WebGLQuery"sv,
|
||||
"WebGLRenderbuffer"sv,
|
||||
"WebGLRenderingContext"sv,
|
||||
"WebGLSampler"sv,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user