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
6 changes: 2 additions & 4 deletions core/src/avm2/globals/flash/display3D/Context3D.as
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,13 @@ package flash.display3D {
):void;

[API("676")]
public function setProgramConstantsFromByteArray(
public native function setProgramConstantsFromByteArray(
programType:String,
firstRegister:int,
numRegisters:int,
data:ByteArray,
dataOffset:uint
):void {
stub_method("flash.display3D.Context3D", "setProgramConstantsFromByteArray");
}
):void;

public native function setColorMask(red:Boolean, green:Boolean, blue:Boolean, alpha:Boolean):void;

Expand Down
67 changes: 63 additions & 4 deletions core/src/avm2/globals/flash/display3D/context_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
} else if &*program_type == b"fragment" {
ProgramType::Fragment
} else {
panic!("Unknown program type {program_type:?}");
return Err(make_error_2008(activation, "programType"));

Check warning on line 305 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (305)

Check warning on line 305 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (305)

Check warning on line 305 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (305)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cover those uncovered lines with tests too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was intending to, guess I missed this one.

};

let first_register = args.get_u32(1);
Expand Down Expand Up @@ -359,7 +359,7 @@
} else if &*program_type == b"fragment" {
ProgramType::Fragment
} else {
panic!("Unknown program type {program_type:?}");
return Err(make_error_2008(activation, "programType"));

Check warning on line 362 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (362)

Check warning on line 362 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (362)

Check warning on line 362 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (362)
};

let first_register = args.get_u32(1);
Expand All @@ -371,8 +371,13 @@

let to_take = if num_registers != -1 {
// Each register requires 4 floating-point values
// FIXME - throw an error if 'vector' is too small
num_registers as usize * 4
let required = num_registers as usize * 4;

if vector.length() < required {
return Err(make_error_3669(activation));
}

required
} else {
vector.length()
};
Expand All @@ -388,6 +393,60 @@
Ok(Value::Undefined)
}

pub fn set_program_constants_from_byte_array<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Value<'gc>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let this = this.as_object().unwrap();

if let Some(context) = this.as_context_3d() {
let program_type = args.get_string(activation, 0);

let program_type = if &*program_type == b"vertex" {
ProgramType::Vertex
} else if &*program_type == b"fragment" {
ProgramType::Fragment

Check warning on line 409 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (409)

Check warning on line 409 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (409)

Check warning on line 409 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (409)
} else {
return Err(make_error_2008(activation, "programType"));
};

let first_register = args.get_u32(1);
let num_registers = args.get_i32(2);

let data = args.get_object(activation, 3, "data")?;
let data = data.as_bytearray().expect("Parameter must be a ByteArray");

let byte_offset = args.get_u32(4) as usize;

// Negative numRegisters is invalid for ByteArray (unlike Vector which treats -1 as "use all")
let num_registers =
usize::try_from(num_registers).map_err(|_| make_error_3669(activation))?;

let required_bytes = num_registers * 16;
let data_len = data.len();

if byte_offset >= data_len || data_len - byte_offset < required_bytes {
return Err(make_error_3669(activation));
}

let num_floats = num_registers * 4;
let mut raw_data = Vec::with_capacity(num_floats);

for i in 0..num_floats {
let float_offset = byte_offset + i * 4;
let value = data
.read_float_at(float_offset)
.expect("Already validated bounds");
raw_data.push(value);
}

context.set_program_constants_from_matrix(program_type, first_register, raw_data);
}

Check warning on line 445 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (445)

Check warning on line 445 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (445)

Check warning on line 445 in core/src/avm2/globals/flash/display3D/context_3d.rs

View workflow job for this annotation

GitHub Actions / Coverage Report

Coverage

Uncovered line (445)

Ok(Value::Undefined)
}

pub fn clear<'gc>(
_activation: &mut Activation<'_, 'gc>,
this: Value<'gc>,
Expand Down
Loading
Loading