Jump to content

  • Log In with Google      Sign In   
  • Create Account

BlackJoker

Member Since 28 Feb 2013
Offline Last Active Today, 05:20 AM

Posts I've Made

In Topic: False negative result in bounding frustum test

Yesterday, 02:59 PM

No, I tryied different approaches and they all lead to the same result.

Regarding incorrect translation of BB - I am not sure, because all intersection tests passed correctly. If I translate my OBB incorrectly, it must affect intersections too, but its not, So have no idea now. Maybe you cna share your algorithm for frustum culling? Maybe I am missing something here (some space translations or something else?


In Topic: Issue with convertion C++ code to C# for TGA loading

26 May 2016 - 01:46 AM

1. Image - its Shaprdx class for storing information and datapointers to the graphics files such as png, bmp, dds and other file formats. 

I dont see any reason to not using it, because later I am creating D3D texture from data, calculated inside Image class.

 

2. Here is code for loading from stream:

NativeFileStream stream = null;
            IntPtr memoryPtr = IntPtr.Zero;
            int size;
            try
            {
                stream = new NativeFileStream(fileName, NativeFileMode.Open, NativeFileAccess.Read);
                size = (int)stream.Length;
                memoryPtr = Utilities.AllocateMemory(size);
                stream.Read(memoryPtr, 0, size);
            }
            catch (Exception)
            {
                if (memoryPtr != IntPtr.Zero)
                    Utilities.FreeMemory(memoryPtr);
                throw;
            }
            finally
            {
                try
                {
                   stream?.Dispose();
                }
                catch {}
            }

            // If everything was fine, load the image from memory
            return Load(memoryPtr, size, false);

As you can see pTGA - its pointer to the memory where whole file is stored. So, it is actually stream data.

 

Update:

after looking to the DDS loader code, I see that there is no need to copy one image to another. Just return new image as I did. So, this question can be closed, I think.


In Topic: Issue with convertion C++ code to C# for TGA loading

25 May 2016 - 03:02 PM

Thanks for help. I had some more problems with by code, but eventually I fixed them and now can load RLE/Expand tga textures as well as non RLA, but one issue is still left.

 

I need to create another instance of Image class to have some destination where I can write to. After all operations finished, I want to copy memory from one location to another using 

Utilities.CopyMemory(image.DataPointer, imgDst.DataPointer, image.PixelBuffer[0].BufferStride);

But problem is that if texture has Expand flag, this function will throw Access violation exception. If texture has no Expand flag, I could copy it without problems.

In general I could just return new image and dispose old, but I am just wondering is it possible just to copy destination image to source in my case?


In Topic: Issue with convertion C++ code to C# for TGA loading

24 May 2016 - 07:11 AM

I think I have found the root cause of the crashing:

else
     {
       int j = (*sPtr & 0x7F) + 1;
       ++sPtr;

Here I take byte value from the memory and add one.

 

Similar string in C++ looks this:

else
   {
    // Literal
    size_t j = (*sPtr & 0x7F) + 1;
    ++sPtr;

For ex., if byte value for particular memory cell is less than 0x7F (for ex. 35), then you will have j = 35+1 = 36. In the same time width of your texture is 10 pixels. So, you will end up returning null, because the following condition will always true:

for (; j > 0; --j, ++x)
    {
      if (x >= description.Width)
       {
          return null;
       }

So, obviously, I translated C++ to C# incorrectly, but how to do it in correct way?


In Topic: Issue with convertion C++ code to C# for TGA loading

22 May 2016 - 01:03 PM

The first thing is that in MS sources for TGA loading you can see that RLE flag will be set to the data even if it actually has no compression.

 

And I am not actually understand how/why MS code working in this case? I dont think they upload non-working solution.


PARTNERS