I don't think you really understand what the individual lines are actually doing.
The texture data is being accessed from a source texture and a new, temporary, software-only texture is created for the warp. If a texture is supposed to be warped, then the renderer will call the texture's "WarpTexture::GetPixels" method, which calls the functions you have modified, depending on whether truecolor mode is active or not.
Code: Select all
auto otherpix = FSoftwareTexture::GetPixelsBgra();
This stores a reference to the source texture in its original form in a variable called 'otherpix'
Code: Select all
WarpedPixelsRgba.Resize(GetWidth() * GetHeight());
The name here is a bit of a misnomer. WarpedPixelsRgba is just a TArray which is GZDoom's standard array type. Resizing simply means it is reallocating the buffer. Without this - you get the crashes that were mentioned earlier in this thread. This line in its unmodified form does not account for the larger textures that are created in the resize, hence the crashing issue.
The reason it works when you do "+1" or some other crazy bullshit like that is because a program's data space is allocated in chunks - so there was enough space for the extra garbage even though it technically was not actually allocated. This would be like if a file on a disk used its extra wasted sector space, which even though the sectors are allocated, the individual bytes are not in use.
As you can guess, putting "+ 1" is a hugely improper fix to this solution and you should not do that.
Always allocate your arrays to the proper size that you actually need!
Code: Select all
WarpBuffer(WarpedPixelsRgba.Data(), otherpix, GetWidth(), GetHeight(), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->shaderspeed, bWarped);
This executes the actual texture warp on the new texture being created, using the 'otherpix' texture that was referenced earlier. In the patch this is fixed so that GetWidth() and GetHeight() are set to the proper size, that way the entire texture is warped, and is warped in the proper (resized) dimensions.
I'm not 100% sure about this, but I would reasonably guess that all this does is unallocate some now unused texture spans.
This simply sets the check at the start of this code block so that it doesn't execute until the next frame. This is important because you only want to generate a warp texture once per frame; not once per pixel.
I don't think you really understand what the individual lines are actually doing.
The texture data is being accessed from a source texture and a new, temporary, software-only texture is created for the warp. If a texture is supposed to be warped, then the renderer will call the texture's "WarpTexture::GetPixels" method, which calls the functions you have modified, depending on whether truecolor mode is active or not.
[code] auto otherpix = FSoftwareTexture::GetPixelsBgra();[/code]
This stores a reference to the source texture in its original form in a variable called 'otherpix'
[code] WarpedPixelsRgba.Resize(GetWidth() * GetHeight());[/code]
The name here is a bit of a misnomer. WarpedPixelsRgba is just a TArray which is GZDoom's standard array type. Resizing simply means it is reallocating the buffer. Without this - you get the crashes that were mentioned earlier in this thread. This line in its unmodified form does not account for the larger textures that are created in the resize, hence the crashing issue.
The reason it works when you do "+1" or some other crazy bullshit like that is because a program's data space is allocated in chunks - so there was enough space for the extra garbage even though it technically was not actually allocated. This would be like if a file on a disk used its extra wasted sector space, which even though the sectors are allocated, the individual bytes are not in use.
As you can guess, putting "+ 1" is a hugely improper fix to this solution and you should not do that. [i]Always[/i] allocate your arrays to the proper size that you actually need!
[code] WarpBuffer(WarpedPixelsRgba.Data(), otherpix, GetWidth(), GetHeight(), WidthOffsetMultiplier, HeightOffsetMultiplier, time, mTexture->shaderspeed, bWarped);[/code]
This executes the actual texture warp on the new texture being created, using the 'otherpix' texture that was referenced earlier. In the patch this is fixed so that GetWidth() and GetHeight() are set to the proper size, that way the entire texture is warped, and is warped in the proper (resized) dimensions.
[code] FreeAllSpans();[/code]
I'm not 100% sure about this, but I would reasonably guess that all this does is unallocate some now unused texture spans.
[code] GenTime[2] = time;[/code]
This simply sets the check at the start of this code block so that it doesn't execute until the next frame. This is important because you only want to generate a warp texture once per frame; not once per pixel.