Skip to content

Commit

Permalink
webgl shaders support wip
Browse files Browse the repository at this point in the history
  • Loading branch information
kalenikaliaksandr committed Jan 22, 2024
1 parent f1347bc commit df9a690
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ static bool is_platform_object(Type const& type)
"URLSearchParams"sv,
"VideoTrack"sv,
"VideoTrackList"sv,
"WebGLObject"sv,
"WebGLShader"sv,
"WebGLProgram"sv,
"WebGLBuffer"sv,
"WebGLRenderingContext"sv,
"Window"sv,
"WritableStream"sv,
Expand Down
16 changes: 16 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>

namespace Web::WebGL {

class WebGLBuffer : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(WebGLBuffer, Bindings::PlatformObject);

public:
WebGLBuffer(JS::Realm& realm)
: PlatformObject(realm) {};
};

}
5 changes: 5 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLBuffer.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <WebGL/WebGLObject.idl>

[Exposed=(Window,Worker)]
interface WebGLBuffer : WebGLObject {
};
Empty file.
3 changes: 3 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLObject.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Exposed=(Window,Worker)]
interface WebGLObject {
};
16 changes: 16 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLProgram.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>

namespace Web::WebGL {

class WebGLProgram : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(WebGLProgram, Bindings::PlatformObject);

public:
WebGLProgram(JS::Realm& realm)
: PlatformObject(realm) {};
};

}
5 changes: 5 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLProgram.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <WebGL/WebGLObject.idl>

[Exposed=(Window,Worker)]
interface WebGLProgram : WebGLObject {
};
76 changes: 76 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ void WebGLRenderingContextBase::active_texture(GLenum texture)
m_context->gl_active_texture(texture);
}

void WebGLRenderingContextBase::attach_shader(JS::NonnullGCPtr<WebGLProgram> program, JS::NonnullGCPtr<WebGLShader> shader) const
{
(void)program;
(void)shader;
}

void WebGLRenderingContextBase::bind_buffer(GLenum target, JS::GCPtr<WebGLBuffer> buffer) const
{
(void)target;
(void)buffer;
}

void WebGLRenderingContextBase::clear(GLbitfield mask)
{
if (m_context_lost)
Expand Down Expand Up @@ -181,6 +193,54 @@ void WebGLRenderingContextBase::color_mask(GLboolean red, GLboolean green, GLboo
m_context->gl_color_mask(red, green, blue, alpha);
}

void WebGLRenderingContextBase::compile_shader(JS::NonnullGCPtr<WebGLShader> shader) const
{
(void)shader;
}

GLint WebGLRenderingContextBase::get_attrib_location(JS::NonnullGCPtr<WebGLProgram> program, String const& name) const
{
(void)program;
(void)name;
return 0;
}

Optional<String> WebGLRenderingContextBase::get_shader_info_log(JS::NonnullGCPtr<WebGLShader> shader) const
{
(void)shader;
return {};
}

WebIDL::ExceptionOr<JS::Value> WebGLRenderingContextBase::get_program_parameter(JS::NonnullGCPtr<WebGLProgram> program, GLenum pname) const
{
(void)program;
(void)pname;
return JS::js_null();
}

WebIDL::ExceptionOr<JS::Value> WebGLRenderingContextBase::get_shader_parameter(JS::NonnullGCPtr<WebGLShader> shader, GLenum pname) const
{
(void)shader;
(void)pname;
return JS::js_null();
}

JS::GCPtr<WebGLBuffer> WebGLRenderingContextBase::create_buffer()
{
return heap().allocate_without_realm<WebGLBuffer>(realm());
}

JS::GCPtr<WebGLProgram> WebGLRenderingContextBase::create_program()
{
return heap().allocate_without_realm<WebGLProgram>(realm());
}

JS::GCPtr<WebGLShader> WebGLRenderingContextBase::create_shader(GLenum type)
{
(void)type;
return heap().allocate_without_realm<WebGLShader>(realm());
}

void WebGLRenderingContextBase::cull_face(GLenum mode)
{
if (m_context_lost)
Expand Down Expand Up @@ -277,6 +337,11 @@ void WebGLRenderingContextBase::line_width(GLfloat width)
m_context->gl_line_width(width);
}

void WebGLRenderingContextBase::link_program(JS::NonnullGCPtr<WebGLProgram> program) const
{
(void)program;
}

void WebGLRenderingContextBase::polygon_offset(GLfloat factor, GLfloat units)
{
if (m_context_lost)
Expand All @@ -295,6 +360,12 @@ void WebGLRenderingContextBase::scissor(GLint x, GLint y, GLsizei width, GLsizei
m_context->gl_scissor(x, y, width, height);
}

void WebGLRenderingContextBase::shader_source(JS::NonnullGCPtr<WebGLShader> shader, String const& source) const
{
(void)shader;
(void)source;
}

void WebGLRenderingContextBase::stencil_op(GLenum fail, GLenum zfail, GLenum zpass)
{
if (m_context_lost)
Expand All @@ -313,6 +384,11 @@ void WebGLRenderingContextBase::stencil_op_separate(GLenum face, GLenum fail, GL
m_context->gl_stencil_op_separate(face, fail, zfail, zpass);
}

void WebGLRenderingContextBase::use_program(JS::GCPtr<WebGLProgram> program) const
{
(void)program;
}

void WebGLRenderingContextBase::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
{
if (m_context_lost)
Expand Down
21 changes: 21 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>
#include <LibWeb/WebGL/OpenGLContext.h>
#include <LibWeb/WebGL/WebGLBuffer.h>
#include <LibWeb/WebGL/WebGLContextAttributes.h>
#include <LibWeb/WebGL/WebGLProgram.h>
#include <LibWeb/WebGL/WebGLShader.h>

namespace Web::WebGL {

Expand All @@ -36,12 +39,25 @@ class WebGLRenderingContextBase : public Bindings::PlatformObject {
JS::Object* get_extension(String const& name) const;

void active_texture(GLenum texture);
void attach_shader(JS::NonnullGCPtr<WebGLProgram> program, JS::NonnullGCPtr<WebGLShader> shader) const;
void bind_buffer(GLenum target, JS::GCPtr<WebGLBuffer> buffer) const;

void clear(GLbitfield mask);
void clear_color(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
void clear_depth(GLclampf depth);
void clear_stencil(GLint s);
void color_mask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
void compile_shader(JS::NonnullGCPtr<WebGLShader> shader) const;

GLint get_attrib_location(JS::NonnullGCPtr<WebGLProgram> program, String const& name) const;

Optional<String> get_shader_info_log(JS::NonnullGCPtr<WebGLShader> shader) const;
WebIDL::ExceptionOr<JS::Value> get_program_parameter(JS::NonnullGCPtr<WebGLProgram> program, GLenum pname) const;
WebIDL::ExceptionOr<JS::Value> get_shader_parameter(JS::NonnullGCPtr<WebGLShader> shader, GLenum pname) const;

JS::GCPtr<WebGLBuffer> create_buffer();
JS::GCPtr<WebGLProgram> create_program();
JS::GCPtr<WebGLShader> create_shader(GLenum type);

void cull_face(GLenum mode);

Expand All @@ -57,13 +73,18 @@ class WebGLRenderingContextBase : public Bindings::PlatformObject {
GLenum get_error();

void line_width(GLfloat width);
void link_program(JS::NonnullGCPtr<WebGLProgram> program) const;
void polygon_offset(GLfloat factor, GLfloat units);

void scissor(GLint x, GLint y, GLsizei width, GLsizei height);

void shader_source(JS::NonnullGCPtr<WebGLShader> shader, String const& source) const;

void stencil_op(GLenum fail, GLenum zfail, GLenum zpass);
void stencil_op_separate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);

void use_program(JS::GCPtr<WebGLProgram> program) const;

void viewport(GLint x, GLint y, GLsizei width, GLsizei height);

protected:
Expand Down
21 changes: 21 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#import <HTML/HTMLCanvasElement.idl>
#import <WebGL/Types.idl>
#import <WebGL/WebGLProgram.idl>
#import <WebGL/WebGLShader.idl>
#import <WebGL/WebGLBuffer.idl>

dictionary WebGLContextAttributes {
boolean alpha = true;
Expand Down Expand Up @@ -29,12 +32,19 @@ interface mixin WebGLRenderingContextBase {
object? getExtension(DOMString name);

undefined activeTexture(GLenum texture);
undefined attachShader(WebGLProgram program, WebGLShader shader);
undefined bindBuffer(GLenum target, WebGLBuffer? buffer);

undefined clear(GLbitfield mask);
undefined clearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
undefined clearDepth(GLclampf depth);
undefined clearStencil(GLint s);
undefined colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
undefined compileShader(WebGLShader shader);

WebGLBuffer? createBuffer();
WebGLProgram? createProgram();
WebGLShader? createShader(GLenum type);

undefined cullFace(GLenum mode);

Expand All @@ -47,16 +57,27 @@ interface mixin WebGLRenderingContextBase {

undefined frontFace(GLenum mode);

[WebGLHandlesContextLoss] GLint getAttribLocation(WebGLProgram program, DOMString name);

GLenum getError();

any getProgramParameter(WebGLProgram program, GLenum pname);
any getShaderParameter(WebGLShader shader, GLenum pname);
DOMString? getShaderInfoLog(WebGLShader shader);

undefined lineWidth(GLfloat width);
undefined linkProgram(WebGLProgram program);
undefined polygonOffset(GLfloat factor, GLfloat units);

undefined scissor(GLint x, GLint y, GLsizei width, GLsizei height);

undefined shaderSource(WebGLShader shader, DOMString source);

undefined stencilOp(GLenum fail, GLenum zfail, GLenum zpass);
undefined stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass);

undefined useProgram(WebGLProgram? program);

undefined viewport(GLint x, GLint y, GLsizei width, GLsizei height);

// Enums
Expand Down
16 changes: 16 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLShader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h>

namespace Web::WebGL {

class WebGLShader : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(WebGLShader, Bindings::PlatformObject);

public:
WebGLShader(JS::Realm& realm)
: PlatformObject(realm) {};
};

}
5 changes: 5 additions & 0 deletions Userland/Libraries/LibWeb/WebGL/WebGLShader.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <WebGL/WebGLObject.idl>

[Exposed=(Window,Worker)]
interface WebGLShader : WebGLObject {
};

0 comments on commit df9a690

Please sign in to comment.