Skip to content

Commit e165302

Browse files
feat(webgl): implement vertexAttribI4i, vertexAttribI4ui, vertexAttribI4iv, and vertexAttribI4uiv methods with argument validation
1 parent a9a8afa commit e165302

File tree

1 file changed

+164
-8
lines changed

1 file changed

+164
-8
lines changed

src/client/script_bindings/webgl/webgl2_rendering_context.cpp

Lines changed: 164 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,36 +1186,192 @@ namespace endor
11861186
{
11871187
Isolate *isolate = args.GetIsolate();
11881188
HandleScope scope(isolate);
1189+
Local<Context> context = isolate->GetCurrentContext();
11891190

1190-
isolate->ThrowException(Exception::Error(
1191-
MakeMethodError(isolate, "vertexAttribI4i", "Not implemented")));
1191+
if (args.Length() < 5)
1192+
{
1193+
isolate->ThrowException(Exception::TypeError(
1194+
MakeMethodArgCountError(isolate, "vertexAttribI4i", 5, args.Length())));
1195+
return;
1196+
}
1197+
for (int i = 0; i < 5; ++i)
1198+
{
1199+
if (!args[i]->IsNumber())
1200+
{
1201+
isolate->ThrowException(Exception::TypeError(
1202+
MakeMethodArgTypeError(isolate, "vertexAttribI4i", i, "number", args[i])));
1203+
return;
1204+
}
1205+
}
1206+
1207+
int index = args[0]->Int32Value(context).ToChecked();
1208+
int v0 = args[1]->Int32Value(context).ToChecked();
1209+
int v1 = args[2]->Int32Value(context).ToChecked();
1210+
int v2 = args[3]->Int32Value(context).ToChecked();
1211+
int v3 = args[4]->Int32Value(context).ToChecked();
1212+
1213+
handle()->vertexAttribI4i(index, v0, v1, v2, v3);
1214+
args.GetReturnValue().SetUndefined();
11921215
}
11931216

11941217
void WebGL2RenderingContext::VertexAttribI4ui(const v8::FunctionCallbackInfo<v8::Value> &args)
11951218
{
11961219
Isolate *isolate = args.GetIsolate();
11971220
HandleScope scope(isolate);
1221+
Local<Context> context = isolate->GetCurrentContext();
11981222

1199-
isolate->ThrowException(Exception::Error(
1200-
MakeMethodError(isolate, "vertexAttribI4ui", "Not implemented")));
1223+
if (args.Length() < 5)
1224+
{
1225+
isolate->ThrowException(Exception::TypeError(
1226+
MakeMethodArgCountError(isolate, "vertexAttribI4ui", 5, args.Length())));
1227+
return;
1228+
}
1229+
for (int i = 0; i < 5; ++i)
1230+
{
1231+
if (!args[i]->IsNumber())
1232+
{
1233+
isolate->ThrowException(Exception::TypeError(
1234+
MakeMethodArgTypeError(isolate, "vertexAttribI4ui", i, "number", args[i])));
1235+
return;
1236+
}
1237+
}
1238+
1239+
int index = args[0]->Int32Value(context).ToChecked();
1240+
uint32_t v0 = args[1]->Uint32Value(context).ToChecked();
1241+
uint32_t v1 = args[2]->Uint32Value(context).ToChecked();
1242+
uint32_t v2 = args[3]->Uint32Value(context).ToChecked();
1243+
uint32_t v3 = args[4]->Uint32Value(context).ToChecked();
1244+
1245+
handle()->vertexAttribI4ui(index, v0, v1, v2, v3);
1246+
args.GetReturnValue().SetUndefined();
12011247
}
12021248

12031249
void WebGL2RenderingContext::VertexAttribI4iv(const v8::FunctionCallbackInfo<v8::Value> &args)
12041250
{
12051251
Isolate *isolate = args.GetIsolate();
12061252
HandleScope scope(isolate);
1253+
Local<Context> context = isolate->GetCurrentContext();
12071254

1208-
isolate->ThrowException(Exception::Error(
1209-
MakeMethodError(isolate, "vertexAttribI4iv", "Not implemented")));
1255+
if (args.Length() < 2)
1256+
{
1257+
isolate->ThrowException(Exception::TypeError(
1258+
MakeMethodArgCountError(isolate, "vertexAttribI4iv", 2, args.Length())));
1259+
return;
1260+
}
1261+
if (!args[0]->IsNumber())
1262+
{
1263+
isolate->ThrowException(Exception::TypeError(
1264+
MakeMethodArgTypeError(isolate, "vertexAttribI4iv", 0, "number", args[0])));
1265+
return;
1266+
}
1267+
if (!args[1]->IsInt32Array() && !args[1]->IsArray())
1268+
{
1269+
isolate->ThrowException(Exception::TypeError(
1270+
MakeMethodArgTypeError(isolate, "vertexAttribI4iv", 1, "Int32Array or Array", args[1])));
1271+
return;
1272+
}
1273+
1274+
int index = args[0]->Int32Value(context).ToChecked();
1275+
std::vector<int> values;
1276+
1277+
if (args[1]->IsInt32Array())
1278+
{
1279+
auto data = args[1].As<Int32Array>();
1280+
auto arrayBuffer = data->Buffer();
1281+
if (arrayBuffer.IsEmpty())
1282+
{
1283+
isolate->ThrowException(Exception::TypeError(
1284+
MakeMethodError(isolate, "vertexAttribI4iv", "Invalid Int32Array")));
1285+
return;
1286+
}
1287+
auto bufferData = static_cast<int32_t *>(arrayBuffer->GetBackingStore()->Data()) + data->ByteOffset() / sizeof(int32_t);
1288+
values.assign(bufferData, bufferData + data->Length());
1289+
}
1290+
else
1291+
{
1292+
auto arr = args[1].As<Array>();
1293+
uint32_t length = arr->Length();
1294+
values.reserve(length);
1295+
for (uint32_t i = 0; i < length; ++i)
1296+
{
1297+
auto item = arr->Get(context, i).ToLocalChecked();
1298+
values.push_back(item->Int32Value(context).ToChecked());
1299+
}
1300+
}
1301+
1302+
if (values.size() < 4)
1303+
{
1304+
isolate->ThrowException(Exception::TypeError(
1305+
MakeMethodError(isolate, "vertexAttribI4iv", "Expected at least 4 components")));
1306+
return;
1307+
}
1308+
1309+
handle()->vertexAttribI4iv(index, values);
1310+
args.GetReturnValue().SetUndefined();
12101311
}
12111312

12121313
void WebGL2RenderingContext::VertexAttribI4uiv(const v8::FunctionCallbackInfo<v8::Value> &args)
12131314
{
12141315
Isolate *isolate = args.GetIsolate();
12151316
HandleScope scope(isolate);
1317+
Local<Context> context = isolate->GetCurrentContext();
12161318

1217-
isolate->ThrowException(Exception::Error(
1218-
MakeMethodError(isolate, "vertexAttribI4uiv", "Not implemented")));
1319+
if (args.Length() < 2)
1320+
{
1321+
isolate->ThrowException(Exception::TypeError(
1322+
MakeMethodArgCountError(isolate, "vertexAttribI4uiv", 2, args.Length())));
1323+
return;
1324+
}
1325+
if (!args[0]->IsNumber())
1326+
{
1327+
isolate->ThrowException(Exception::TypeError(
1328+
MakeMethodArgTypeError(isolate, "vertexAttribI4uiv", 0, "number", args[0])));
1329+
return;
1330+
}
1331+
if (!args[1]->IsUint32Array() && !args[1]->IsArray())
1332+
{
1333+
isolate->ThrowException(Exception::TypeError(
1334+
MakeMethodArgTypeError(isolate, "vertexAttribI4uiv", 1, "Uint32Array or Array", args[1])));
1335+
return;
1336+
}
1337+
1338+
int index = args[0]->Int32Value(context).ToChecked();
1339+
std::vector<uint32_t> values;
1340+
1341+
if (args[1]->IsUint32Array())
1342+
{
1343+
auto data = args[1].As<Uint32Array>();
1344+
auto arrayBuffer = data->Buffer();
1345+
if (arrayBuffer.IsEmpty())
1346+
{
1347+
isolate->ThrowException(Exception::TypeError(
1348+
MakeMethodError(isolate, "vertexAttribI4uiv", "Invalid Uint32Array")));
1349+
return;
1350+
}
1351+
auto bufferData = static_cast<uint32_t *>(arrayBuffer->GetBackingStore()->Data()) + data->ByteOffset() / sizeof(uint32_t);
1352+
values.assign(bufferData, bufferData + data->Length());
1353+
}
1354+
else
1355+
{
1356+
auto arr = args[1].As<Array>();
1357+
uint32_t length = arr->Length();
1358+
values.reserve(length);
1359+
for (uint32_t i = 0; i < length; ++i)
1360+
{
1361+
auto item = arr->Get(context, i).ToLocalChecked();
1362+
values.push_back(item->Uint32Value(context).ToChecked());
1363+
}
1364+
}
1365+
1366+
if (values.size() < 4)
1367+
{
1368+
isolate->ThrowException(Exception::TypeError(
1369+
MakeMethodError(isolate, "vertexAttribI4uiv", "Expected at least 4 components")));
1370+
return;
1371+
}
1372+
1373+
handle()->vertexAttribI4uiv(index, values);
1374+
args.GetReturnValue().SetUndefined();
12191375
}
12201376

12211377
void WebGL2RenderingContext::GetUniformIndices(const FunctionCallbackInfo<Value> &args)

0 commit comments

Comments
 (0)