Skip to content

Commit

Permalink
Moved some ivec2's to uvec2's
Browse files Browse the repository at this point in the history
  • Loading branch information
Raikiri committed Oct 24, 2024
1 parent 137339b commit d74166b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion LegitScript/include/LegitScriptEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace ls
struct CachedImageRequest
{
ls::PixelFormats pixel_format;
ivec2 size;
uvec2 size;
Image::Id id;
bool operator < (const CachedImageRequest &other) const
{
Expand Down
29 changes: 14 additions & 15 deletions LegitScript/source/RenderGraphScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ struct RenderGraphScript::Impl

struct ImageInfo
{
ivec2 size;
uvec2 size;
ls::PixelFormats pixel_format;
size_t GetMipsCount() const
{
Expand All @@ -222,9 +222,9 @@ struct RenderGraphScript::Impl
for(;tmp_size.x > 1 && tmp_size.y > 1; tmp_size.x /= 2, tmp_size.y /= 2, mips_count++);
return mips_count;
}
ivec2 GetMipSize(int mip_level) const
uvec2 GetMipSize(uint mip_level) const
{
return ivec2{size.x >> mip_level, size.y >> mip_level};
return uvec2{size.x >> mip_level, size.y >> mip_level};
}
};
std::vector<ImageInfo> image_infos;
Expand Down Expand Up @@ -277,7 +277,7 @@ ScriptEvents RenderGraphScript::Impl::RunScript(const std::vector<ContextInput>
script_events = ScriptEvents();
SetContextInputs(context_inputs);

ivec2 swapchain_size = this->script_context.GetContextRef<ivec2>("@swapchain_size");
uvec2 swapchain_size = this->script_context.GetContextRef<uvec2>("@swapchain_size");
image_infos.clear();
image_infos.push_back({swapchain_size, ls::PixelFormats::rgba8});

Expand Down Expand Up @@ -439,29 +439,28 @@ void RenderGraphScript::Impl::RegisterImageType()
{
as_script_engine->RegisterType<ls::Image>("Image");

as_script_engine->RegisterGlobalFunction("Image GetMippedImage(int width, int height, PixelFormats pixel_format)", [this](asIScriptGeneric *gen)
as_script_engine->RegisterGlobalFunction("Image GetMippedImage(uvec2 size, PixelFormats pixel_format)", [this](asIScriptGeneric *gen)
{
int width = gen->GetArgDWord(0);
int height = gen->GetArgDWord(1);
auto pixel_format = ls::PixelFormats(gen->GetArgDWord(2));
auto size = *(ls::uvec2*)gen->GetArgObject(0);
auto pixel_format = ls::PixelFormats(gen->GetArgDWord(1));

Image::Id id = this->image_infos.size();
this->image_infos.push_back({ivec2{width, height}, pixel_format});
this->image_infos.push_back({size, pixel_format});

ls::CachedImageRequest image_request;
image_request.id = id;
image_request.pixel_format = pixel_format;
image_request.size = {width, height};
image_request.size = size;
this->script_events.context_requests.push_back(image_request);

ls::Image img;
img.id = id;
img.mip_range = ivec2{0, int(this->image_infos[id].GetMipsCount())};
gen->SetReturnObject(&img);
});
as_script_engine->RegisterGlobalFunction("Image GetImage(ivec2 size, PixelFormats pixel_format)", [this](asIScriptGeneric *gen)
as_script_engine->RegisterGlobalFunction("Image GetImage(uvec2 size, PixelFormats pixel_format)", [this](asIScriptGeneric *gen)
{
auto size = *(ls::ivec2*)gen->GetArgObject(0);
auto size = *(ls::uvec2*)gen->GetArgObject(0);
auto pixel_format = ls::PixelFormats(gen->GetArgDWord(1));

ls::CachedImageRequest image_request;
Expand Down Expand Up @@ -507,13 +506,13 @@ void RenderGraphScript::Impl::RegisterImageType()

gen->SetReturnObject(&dst_img);
});
as_script_engine->RegisterMethod("Image", "ivec2 GetSize() const", [this](asIScriptGeneric *gen)
as_script_engine->RegisterMethod("Image", "uvec2 GetSize() const", [this](asIScriptGeneric *gen)
{
auto *this_ptr = (ls::Image*)gen->GetObject();
ivec2 mip_size = this->image_infos[this_ptr->id].GetMipSize(this_ptr->mip_range.x);
uvec2 mip_size = this->image_infos[this_ptr->id].GetMipSize(this_ptr->mip_range.x);
gen->SetReturnObject(&mip_size);
});
as_script_engine->RegisterMethod("Image", "int GetMipsCount() const", [this](asIScriptGeneric *gen)
as_script_engine->RegisterMethod("Image", "uint GetMipsCount() const", [this](asIScriptGeneric *gen)
{
auto *this_ptr = (ls::Image*)gen->GetObject();
int mips_count = this_ptr->mip_range.y - this_ptr->mip_range.x;
Expand Down

0 comments on commit d74166b

Please sign in to comment.