Skip to content

Commit 63503c1

Browse files
Lubrsikalenikaliaksandr
authored andcommitted
LibWeb/WebGL2: Implement getUniformIndices
1 parent 54d95fc commit 63503c1

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Libraries/LibWeb/WebGL/WebGL2RenderingContextBase.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ interface mixin WebGL2RenderingContextBase {
418418
undefined bindBufferBase(GLenum target, GLuint index, WebGLBuffer? buffer);
419419
undefined bindBufferRange(GLenum target, GLuint index, WebGLBuffer? buffer, GLintptr offset, GLsizeiptr size);
420420
[FIXME] any getIndexedParameter(GLenum target, GLuint index);
421-
[FIXME] sequence<GLuint>? getUniformIndices(WebGLProgram program, sequence<DOMString> uniformNames);
421+
sequence<GLuint>? getUniformIndices(WebGLProgram program, sequence<DOMString> uniformNames);
422422
any getActiveUniforms(WebGLProgram program, sequence<GLuint> uniformIndices, GLenum pname);
423423
GLuint getUniformBlockIndex(WebGLProgram program, DOMString uniformBlockName);
424424
any getActiveUniformBlockParameter(WebGLProgram program, GLuint uniformBlockIndex, GLenum pname);

Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,36 @@ void WebGL2RenderingContextImpl::bind_buffer_range(WebIDL::UnsignedLong target,
10351035
glBindBufferRange(target, index, buffer_handle, offset, size);
10361036
}
10371037

1038+
Optional<Vector<WebIDL::UnsignedLong>> WebGL2RenderingContextImpl::get_uniform_indices(GC::Root<WebGLProgram> program, Vector<String> const& uniform_names)
1039+
{
1040+
m_context->make_current();
1041+
1042+
auto handle_or_error = program->handle(this);
1043+
if (handle_or_error.is_error()) {
1044+
set_error(GL_INVALID_OPERATION);
1045+
return OptionalNone {};
1046+
}
1047+
1048+
auto program_handle = handle_or_error.release_value();
1049+
1050+
Vector<Vector<GLchar>> uniform_names_strings;
1051+
uniform_names_strings.ensure_capacity(uniform_names.size());
1052+
for (auto const& uniform_name : uniform_names) {
1053+
uniform_names_strings.unchecked_append(null_terminated_string(uniform_name));
1054+
}
1055+
1056+
Vector<GLchar const*> uniform_names_characters;
1057+
uniform_names_characters.ensure_capacity(uniform_names_strings.size());
1058+
for (auto const& uniform_name_string : uniform_names_strings) {
1059+
uniform_names_characters.unchecked_append(uniform_name_string.data());
1060+
}
1061+
1062+
auto result_buffer = MUST(ByteBuffer::create_zeroed(uniform_names_characters.size() * sizeof(WebIDL::UnsignedLong)));
1063+
auto result_span = result_buffer.bytes().reinterpret<WebIDL::UnsignedLong>();
1064+
glGetUniformIndices(program_handle, uniform_names_characters.size(), uniform_names_characters.data(), result_span.data());
1065+
return Vector<WebIDL::UnsignedLong> { result_span };
1066+
}
1067+
10381068
JS::Value WebGL2RenderingContextImpl::get_active_uniforms(GC::Root<WebGLProgram> program, Vector<WebIDL::UnsignedLong> uniform_indices, WebIDL::UnsignedLong pname)
10391069
{
10401070
m_context->make_current();

Libraries/LibWeb/WebGL/WebGL2RenderingContextImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class WebGL2RenderingContextImpl : public WebGLRenderingContextImpl {
9090
void resume_transform_feedback();
9191
void bind_buffer_base(WebIDL::UnsignedLong target, WebIDL::UnsignedLong index, GC::Root<WebGLBuffer> buffer);
9292
void bind_buffer_range(WebIDL::UnsignedLong target, WebIDL::UnsignedLong index, GC::Root<WebGLBuffer> buffer, WebIDL::LongLong offset, WebIDL::LongLong size);
93+
Optional<Vector<WebIDL::UnsignedLong>> get_uniform_indices(GC::Root<WebGLProgram> program, Vector<String> const& uniform_names);
9394
JS::Value get_active_uniforms(GC::Root<WebGLProgram> program, Vector<WebIDL::UnsignedLong> uniform_indices, WebIDL::UnsignedLong pname);
9495
WebIDL::UnsignedLong get_uniform_block_index(GC::Root<WebGLProgram> program, String uniform_block_name);
9596
JS::Value get_active_uniform_block_parameter(GC::Root<WebGLProgram> program, WebIDL::UnsignedLong uniform_block_index, WebIDL::UnsignedLong pname);

0 commit comments

Comments
 (0)