Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/client/graphics/webgl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,62 @@ namespace endor
sendCommandBufferRequest(req);
}

void WebGLContext::vertexAttrib1fv(const WebGLAttribLocation &index, const vector<float> values)
{
auto req = VertexAttrib1fvCommandBufferRequest(index.programId, index.name, values);
if (index.index.has_value())
req.setLoc(index.index.value());
sendCommandBufferRequest(req);
}

void WebGLContext::vertexAttrib1fv(int index, const vector<float> values)
{
auto req = VertexAttrib1fvCommandBufferRequest(0, index, values);
sendCommandBufferRequest(req);
}

void WebGLContext::vertexAttrib2fv(const WebGLAttribLocation &index, const vector<float> values)
{
auto req = VertexAttrib2fvCommandBufferRequest(index.programId, index.name, values);
if (index.index.has_value())
req.setLoc(index.index.value());
sendCommandBufferRequest(req);
}

void WebGLContext::vertexAttrib2fv(int index, const vector<float> values)
{
auto req = VertexAttrib2fvCommandBufferRequest(0, index, values);
sendCommandBufferRequest(req);
}

void WebGLContext::vertexAttrib3fv(const WebGLAttribLocation &index, const vector<float> values)
{
auto req = VertexAttrib3fvCommandBufferRequest(index.programId, index.name, values);
if (index.index.has_value())
req.setLoc(index.index.value());
sendCommandBufferRequest(req);
}

void WebGLContext::vertexAttrib3fv(int index, const vector<float> values)
{
auto req = VertexAttrib3fvCommandBufferRequest(0, index, values);
sendCommandBufferRequest(req);
}

void WebGLContext::vertexAttrib4fv(const WebGLAttribLocation &index, const vector<float> values)
{
auto req = VertexAttrib4fvCommandBufferRequest(index.programId, index.name, values);
if (index.index.has_value())
req.setLoc(index.index.value());
sendCommandBufferRequest(req);
}

void WebGLContext::vertexAttrib4fv(int index, const vector<float> values)
{
auto req = VertexAttrib4fvCommandBufferRequest(0, index, values);
sendCommandBufferRequest(req);
}

optional<WebGLActiveInfo> WebGLContext::getActiveAttrib(shared_ptr<WebGLProgram> program, unsigned int index)
{
assert(program != nullptr && "Program is not null");
Expand Down
8 changes: 8 additions & 0 deletions src/client/graphics/webgl_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ namespace endor
void vertexAttrib3f(int index, float v0, float v1, float v2);
void vertexAttrib4f(const WebGLAttribLocation &, float v0, float v1, float v2, float v3);
void vertexAttrib4f(int index, float v0, float v1, float v2, float v3);
void vertexAttrib1fv(const WebGLAttribLocation &, const std::vector<float> values);
void vertexAttrib1fv(int index, const std::vector<float> values);
void vertexAttrib2fv(const WebGLAttribLocation &, const std::vector<float> values);
void vertexAttrib2fv(int index, const std::vector<float> values);
void vertexAttrib3fv(const WebGLAttribLocation &, const std::vector<float> values);
void vertexAttrib3fv(int index, const std::vector<float> values);
void vertexAttrib4fv(const WebGLAttribLocation &, const std::vector<float> values);
void vertexAttrib4fv(int index, const std::vector<float> values);
std::optional<WebGLActiveInfo> getActiveAttrib(std::shared_ptr<WebGLProgram> program, unsigned int index);
std::optional<WebGLActiveInfo> getActiveUniform(std::shared_ptr<WebGLProgram> program, unsigned int index);
std::optional<WebGLAttribLocation> getAttribLocation(std::shared_ptr<WebGLProgram> program, const std::string &name);
Expand Down
136 changes: 136 additions & 0 deletions src/client/script_bindings/webgl/webgl_rendering_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ namespace endor
ADD_WEBGL1_METHOD("vertexAttrib2f", VertexAttrib2f)
ADD_WEBGL1_METHOD("vertexAttrib3f", VertexAttrib3f)
ADD_WEBGL1_METHOD("vertexAttrib4f", VertexAttrib4f)
ADD_WEBGL1_METHOD("vertexAttrib1fv", VertexAttrib1fv)
ADD_WEBGL1_METHOD("vertexAttrib2fv", VertexAttrib2fv)
ADD_WEBGL1_METHOD("vertexAttrib3fv", VertexAttrib3fv)
ADD_WEBGL1_METHOD("vertexAttrib4fv", VertexAttrib4fv)
ADD_WEBGL1_METHOD("getActiveAttrib", GetActiveAttrib)
ADD_WEBGL1_METHOD("getActiveUniform", GetActiveUniform)
ADD_WEBGL1_METHOD("getAttribLocation", GetAttribLocation)
Expand Down Expand Up @@ -4171,6 +4175,138 @@ namespace endor
info.GetReturnValue().SetUndefined();
}

void WebGLRenderingContext::VertexAttrib1fv(const FunctionCallbackInfo<Value> &info)
{
Isolate *isolate = info.GetIsolate();
HandleScope scope(isolate);

if (info.Length() < 2)
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib1fv", "2 arguments required, but fewer were provided")));
return;
}
if (!info[0]->IsNumber())
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib1fv", "First argument must be a number")));
return;
}

Local<Context> context = isolate->GetCurrentContext();
int index = info[0]->Int32Value(context).FromMaybe(0);

std::vector<float> values = GetFloatValuesFromValue(isolate, info[1]);
if (values.size() < 1)
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib1fv", "Expected at least 1 component in the array")));
return;
}

handle()->vertexAttrib1fv(index, values);
info.GetReturnValue().SetUndefined();
}

void WebGLRenderingContext::VertexAttrib2fv(const FunctionCallbackInfo<Value> &info)
{
Isolate *isolate = info.GetIsolate();
HandleScope scope(isolate);

if (info.Length() < 2)
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib2fv", "2 arguments required, but fewer were provided")));
return;
}
if (!info[0]->IsNumber())
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib2fv", "First argument must be a number")));
return;
}

Local<Context> context = isolate->GetCurrentContext();
int index = info[0]->Int32Value(context).FromMaybe(0);

std::vector<float> values = GetFloatValuesFromValue(isolate, info[1]);
if (values.size() < 2)
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib2fv", "Expected at least 2 components in the array")));
return;
}

handle()->vertexAttrib2fv(index, values);
info.GetReturnValue().SetUndefined();
}

void WebGLRenderingContext::VertexAttrib3fv(const FunctionCallbackInfo<Value> &info)
{
Isolate *isolate = info.GetIsolate();
HandleScope scope(isolate);

if (info.Length() < 2)
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib3fv", "2 arguments required, but fewer were provided")));
return;
}
if (!info[0]->IsNumber())
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib3fv", "First argument must be a number")));
return;
}

Local<Context> context = isolate->GetCurrentContext();
int index = info[0]->Int32Value(context).FromMaybe(0);

std::vector<float> values = GetFloatValuesFromValue(isolate, info[1]);
if (values.size() < 3)
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib3fv", "Expected at least 3 components in the array")));
return;
}

handle()->vertexAttrib3fv(index, values);
info.GetReturnValue().SetUndefined();
}

void WebGLRenderingContext::VertexAttrib4fv(const FunctionCallbackInfo<Value> &info)
{
Isolate *isolate = info.GetIsolate();
HandleScope scope(isolate);

if (info.Length() < 2)
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib4fv", "2 arguments required, but fewer were provided")));
return;
}
if (!info[0]->IsNumber())
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib4fv", "First argument must be a number")));
return;
}

Local<Context> context = isolate->GetCurrentContext();
int index = info[0]->Int32Value(context).FromMaybe(0);

std::vector<float> values = GetFloatValuesFromValue(isolate, info[1]);
if (values.size() < 4)
{
isolate->ThrowException(Exception::TypeError(
MakeMethodError(isolate, "vertexAttrib4fv", "Expected at least 4 components in the array")));
return;
}

handle()->vertexAttrib4fv(index, values);
info.GetReturnValue().SetUndefined();
}

void WebGLRenderingContext::VertexAttribPointer(const FunctionCallbackInfo<Value> &info)
{
Isolate *isolate = info.GetIsolate();
Expand Down
4 changes: 4 additions & 0 deletions src/client/script_bindings/webgl/webgl_rendering_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ namespace endor
void VertexAttrib2f(const v8::FunctionCallbackInfo<v8::Value> &info);
void VertexAttrib3f(const v8::FunctionCallbackInfo<v8::Value> &info);
void VertexAttrib4f(const v8::FunctionCallbackInfo<v8::Value> &info);
void VertexAttrib1fv(const v8::FunctionCallbackInfo<v8::Value> &info);
void VertexAttrib2fv(const v8::FunctionCallbackInfo<v8::Value> &info);
void VertexAttrib3fv(const v8::FunctionCallbackInfo<v8::Value> &info);
void VertexAttrib4fv(const v8::FunctionCallbackInfo<v8::Value> &info);
void VertexAttribPointer(const v8::FunctionCallbackInfo<v8::Value> &info);

// Viewport & scissor
Expand Down
76 changes: 76 additions & 0 deletions src/common/command_buffers/details/vertex_attrib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,82 @@ namespace commandbuffers
float v0, v1, v2, v3;
};

// Base class for vector float vertex attribute requests
template <typename Derived, CommandBufferType Type>
class VertexAttribNfvCommandBufferRequest : public SetVertexAttribCommandBufferRequest<Derived, Type>
{
public:
VertexAttribNfvCommandBufferRequest() = delete;
VertexAttribNfvCommandBufferRequest(uint32_t program, const std::string &location_name, const std::vector<float> &values)
: SetVertexAttribCommandBufferRequest<Derived, Type>(program, location_name)
, values(values)
{
}
VertexAttribNfvCommandBufferRequest(uint32_t program, uint32_t index, const std::vector<float> &values)
: SetVertexAttribCommandBufferRequest<Derived, Type>(program, index)
, values(values)
{
}
VertexAttribNfvCommandBufferRequest(const Derived &that, bool clone = false)
: SetVertexAttribCommandBufferRequest<Derived, Type>(that, clone)
, values(that.values)
{
}

std::string toString(const char *line_prefix) const override
{
std::stringstream ss;
ss << SetVertexAttribCommandBufferRequest<Derived, Type>::toString(line_prefix) << "([";
for (size_t i = 0; i < values.size(); ++i)
{
if (i > 0)
ss << ", ";
ss << values[i];
}
ss << "])";
return ss.str();
}

public:
std::vector<float> values;
};

// VertexAttrib1fv command buffer request
class VertexAttrib1fvCommandBufferRequest final
: public VertexAttribNfvCommandBufferRequest<VertexAttrib1fvCommandBufferRequest,
COMMAND_BUFFER_VERTEX_ATTRIB_1FV_REQ>
{
public:
using VertexAttribNfvCommandBufferRequest::VertexAttribNfvCommandBufferRequest;
};

// VertexAttrib2fv command buffer request
class VertexAttrib2fvCommandBufferRequest final
: public VertexAttribNfvCommandBufferRequest<VertexAttrib2fvCommandBufferRequest,
COMMAND_BUFFER_VERTEX_ATTRIB_2FV_REQ>
{
public:
using VertexAttribNfvCommandBufferRequest::VertexAttribNfvCommandBufferRequest;
};

// VertexAttrib3fv command buffer request
class VertexAttrib3fvCommandBufferRequest final
: public VertexAttribNfvCommandBufferRequest<VertexAttrib3fvCommandBufferRequest,
COMMAND_BUFFER_VERTEX_ATTRIB_3FV_REQ>
{
public:
using VertexAttribNfvCommandBufferRequest::VertexAttribNfvCommandBufferRequest;
};

// VertexAttrib4fv command buffer request
class VertexAttrib4fvCommandBufferRequest final
: public VertexAttribNfvCommandBufferRequest<VertexAttrib4fvCommandBufferRequest,
COMMAND_BUFFER_VERTEX_ATTRIB_4FV_REQ>
{
public:
using VertexAttribNfvCommandBufferRequest::VertexAttribNfvCommandBufferRequest;
};

class VertexAttribIPointerCommandBufferRequest final
: public SetVertexAttribCommandBufferRequest<VertexAttribIPointerCommandBufferRequest,
COMMAND_BUFFER_VERTEX_ATTRIB_IPOINTER_REQ>
Expand Down
4 changes: 4 additions & 0 deletions src/common/command_buffers/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
XX(VERTEX_ATTRIB_2F, VertexAttrib2fCommandBufferRequest, "GL::VertexAttrib2f") \
XX(VERTEX_ATTRIB_3F, VertexAttrib3fCommandBufferRequest, "GL::VertexAttrib3f") \
XX(VERTEX_ATTRIB_4F, VertexAttrib4fCommandBufferRequest, "GL::VertexAttrib4f") \
XX(VERTEX_ATTRIB_1FV, VertexAttrib1fvCommandBufferRequest, "GL::VertexAttrib1fv") \
XX(VERTEX_ATTRIB_2FV, VertexAttrib2fvCommandBufferRequest, "GL::VertexAttrib2fv") \
XX(VERTEX_ATTRIB_3FV, VertexAttrib3fvCommandBufferRequest, "GL::VertexAttrib3fv") \
XX(VERTEX_ATTRIB_4FV, VertexAttrib4fvCommandBufferRequest, "GL::VertexAttrib4fv") \
XX(VERTEX_ATTRIB_IPOINTER, VertexAttribIPointerCommandBufferRequest, "GL::VertexAttribIPointer") \
XX(VERTEX_ATTRIB_DIVISOR, VertexAttribDivisorCommandBufferRequest, "GL::VertexAttribDivisor") \
XX(VERTEX_ATTRIB_I4I, VertexAttribI4iCommandBufferRequest, "GL::VertexAttribI4i") \
Expand Down
4 changes: 4 additions & 0 deletions src/common/command_buffers/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ namespace commandbuffers
COMMAND_BUFFER_VERTEX_ATTRIB_2F_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_3F_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_4F_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_1FV_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_2FV_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_3FV_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_4FV_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_IPOINTER_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_DIVISOR_REQ,
COMMAND_BUFFER_VERTEX_ATTRIB_I4I_REQ,
Expand Down
Loading