Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 21 Feb 2008
Offline Last Active Today, 09:52 AM

#5253632 can anyone explain const char*, char, strings, char array

Posted by NightCreature83 on 23 September 2015 - 05:47 AM

Any advanced string type, std::string as well, will inform you of chracter count especialy, when calling .size()

This is not true if the string is UTF enocded. UTF8 and UTF16 can encode a single character in multiple bytes. If you store UTF8 in a std::string size() doesn't guarantee that it corresponds to the number of characters in the string, it will however guarantee the amounts of bytes needed for the buffer, and the same goes for storing a UTF16 string in a std::wstring.

#5253343 can anyone explain const char*, char, strings, char array

Posted by NightCreature83 on 21 September 2015 - 03:31 PM

char* is a pointer which holds the address in memory of a character, for example it can point at a single 'char' variable, or it can point at the address where a sequential array begins.

const char* is such a pointer that is declared constant, which means that any function accepting it promises not to change the values stored in memory at that address. Read-only access to a string is usually the meaning..

const char*

Is not a constant pointer its actually a pointer to a constant char.

char* const

Would have been a constant pointer to a char. There is a difference in this stuff so be careful learn when the pointer is constant and when the actual object the pointer is pointing at is constant.

const char* const

Would be a constant pointer to a constant char.


The difference between the first two is subtle but effectively it means I can assign a new address to the variable that is decalred that way as long as the memory it points at is of const char type, I cannot change the value in the memory location of the pointer. In the second example I can not change the address of the pointer, however I can change the value in the memory location of the pointer. In the last case you cannot either of the two operations above.

char aChar = 'a';
const char* pointerToAConstantChar = &aChar;
char* const constantPointerToAChar = &aChar;
const char* const constantPointerToAConstantChar = &aChar;

char bChar = 'b';

*pointerToAConstantChar = 'B'; //Error: cannot change the value in aChar
pointerToAConstantChar = &bChar;

*constantPointerToAChar = 'B';
constantPointerToAChar = &bChar; //Error: cannot change the pointer

*constantPointerToAConstantChar = 'B'; //Error: cannot change the value in aChar
constantPointerToAConstantChar = &bChar; //Error: cannot change the pointer

#5253280 C++ Question About Objects

Posted by NightCreature83 on 21 September 2015 - 06:44 AM

A final note FYI.

Do not call overriden functions (virtual) from base class ctor. So you cannot do something like:

class Asset {
  Asset(const std::string &foo) { Load(foo); }
  virtual void Load(const std::string &foo) = 0;

class Level : public Asset {
  Level (const std::string &foo) : Asset(foo) { }
  void Load(const std::string &foo) {
    // Pull physics
    // Pull textures
    // Pull sound resources

To build a Level object the runtime first builds the Asset object. When the Asset object ctor is run, it has no information about what's really running and you'll be screwed big way. I think some compilers warn you or even prevent you from doing that. I am 100% sure I have been screwed in the past.

If memory serves, Java allows this for some reasons I don't remember. I'd suggest to be careful with that.


Java and C# allow this because the construction of a derived object runs in the opposite fashion from a C++ object. In Java/C# first the derived object is created with its associated vtable, this means that the constructor knows where to dispatch a virtual function call too. In C++ first the base object is created and then the derived version, calling a virtual function is in that case undefined behaviour for C++.

#5252323 Programming Role Playing Games with DirectX

Posted by NightCreature83 on 15 September 2015 - 03:45 AM

The compiler can also sometimes complain about comments containing non ascii chars, this has tripped me up many a time in the past.

#5250986 C++11 lambda, modifying copied value

Posted by NightCreature83 on 07 September 2015 - 08:13 AM

With = you are capturing variables by value not reference if you use & in the [] it will capture that variable as a reference and you should see the change outside of the lambda.

#5245968 "DxTrace" Linker Error In Visual Studio 2015

Posted by NightCreature83 on 12 August 2015 - 07:14 AM

The function StringVPrintfWorkerW is trying to use the function called __vsnwprintf which your linker cant find at the moment. Tell the linker which .lib file that function is defined in and you will see that the compile will work again. https://msdn.microsoft.com/en-us/library/1kt27hek.aspx

#5245816 What is a wrapper? What is a Decorator?

Posted by NightCreature83 on 11 August 2015 - 01:54 PM

Wrapper and decorator mean about the same it adds some specific functionality to an object/function without touching objects/function that are similar as the object you decorated. Usually you use this when you have a specific need to do something different but you don't need to rewrite a whole new class to do this action.


The wikipedia article about the decorator pattern has a good example of a window decorator for example that adds the ability to have a scrollbar next to a window without having to add the scrollbar functionality to the window class.


Decorators will usually have the same interface that the underlying class has but in the functions where it calls the functions of the class underneath it adds functionality that it has to do to the execution of that function.


The distinction between a wrapper and a decorator is more the pattern in how it is applied, you usually talk about decorators when talking about classes that wrap the functionality of other ones and add a specific functionality to the execution stack. Wrapper functions is more when you wrap call to a method of a global instance in a global function, wrappers are usually nothing more as function wrapped around another one, generally their scope is smaller.


But are used to implement plugable/extendable behavior to an existing class/function that might be black box.

#5245388 D3D12 how to set shader constants (outside of cbuffer)

Posted by NightCreature83 on 10 August 2015 - 01:34 AM

I am still wondering why you want your variable outside of the constant buffer, we have these cbuffers to efficiently update our constants?

#5245077 How to render skybox, then save to a texture?

Posted by NightCreature83 on 08 August 2015 - 05:32 AM

When you bind the SRV you need to make sure you are no longer using the RTV, if you have the DX runtime setup to use the debug version and set the output to warnings, you will get a warning in the output when the SRV is still being used as a RTV.

#5244983 How to render skybox, then save to a texture?

Posted by NightCreature83 on 07 August 2015 - 11:27 AM

btw if you do no rendering between the texture creation, copy and save operation there is nothing in the back buffer and it will be black or what was there last frame. If you do this after the call to clear the bufffer the texture will have the color of the clear color.


You will want to do that copy just before the present call and do the save after the present because a read back from GPU to disc is a costly operation.


Also read the remarks on this topic: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476392%28v=vs.85%29.aspx because the CopyResource call comes with a few requirements that you have to obey for it to work correctly.

#5244951 How to render skybox, then save to a texture?

Posted by NightCreature83 on 07 August 2015 - 09:19 AM

If you want to use the texture as a render target you have to bind it that way  my cube descriptors look like this:

    D3D11_TEXTURE2D_DESC cubeDesc;
    ZeroMemory(&cubeDesc, sizeof(D3D11_TEXTURE3D_DESC));
    cubeDesc.Width = cubeMapWidhtHeight;
    cubeDesc.Height = cubeMapWidhtHeight;
    cubeDesc.MipLevels = 0;
    cubeDesc.ArraySize = 6;
    cubeDesc.SampleDesc.Count = 1;
    cubeDesc.SampleDesc.Quality = 0;
    cubeDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    cubeDesc.Usage = D3D11_USAGE_DEFAULT;
    cubeDesc.CPUAccessFlags = 0;

I am generating a cubemap in my game so thats why the array size is 6 and miscflags are set to be a texturecube.


Just for completeness here is how I setup my descriptors for the RTV and SRV which are used for rendering to it and using it as a texture in game:

//Should create a 6 2D rts here instead
rtDesc.Format = cubeDesc.Format;
rtDesc.Texture2DArray.FirstArraySlice = 0;
rtDesc.Texture2DArray.ArraySize = 6;
rtDesc.Texture2DArray.MipSlice = 0;

// Create the shader resource view for the cubic env map
ZeroMemory(&srvDesc, sizeof(srvDesc));
srvDesc.Format = cubeDesc.Format;
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
srvDesc.TextureCube.MipLevels = 1;
srvDesc.TextureCube.MostDetailedMip = 0;

#5244934 How to render skybox, then save to a texture?

Posted by NightCreature83 on 07 August 2015 - 07:22 AM

Yes this is possible I am assuming you will want to use the resulting texture for something else afterwards in the game. IN that case you will want to do an offscreen render of the sky box into a render target.


Both these tutorials show how this works.




In general it works by replacing the backbuffer with a different rendertarget that you have created. You first ask for the back buffer reference, keep this arround because you will want to restore this after you have drawn to your texture. You then set your new Rendertarget as the back buffer and draw the scene that you want to have displayed in that texture. Restore the orginal back buffer and render the scene that should be seen as the game and use the RenderTarget you created as an input texture to the object you want to show it on or use it for.

#5244611 Clone functions

Posted by NightCreature83 on 05 August 2015 - 04:15 AM

It also depends on the language you're using. Shallow clones can be fine in garbage-collected languages like C# or Java, assuming that having two objects point to the same internal objects is ok (this may cause threading issues, unexpected behavior when contents of object A change when you modify B, etc)

It gets much more dangerous in something like C++ if you're using raw pointers as you may try to then double-delete the shared object (can be mitigated with shared_ptr or similar).

This depends on the usage pattern in C++, if your objects are only holding on to references to other objects the shallow pointer value copy is fine.  I would only provide a copy function into a class when the deep copy is needed and just rely on the compiler provided one if a  shallow copy will do.

#5244602 Including headers from Windows 10 SDK

Posted by NightCreature83 on 05 August 2015 - 01:16 AM




Please clarify what "doesn't get included" means. Do you get an error? If so, what is the exact error message?

#Include <d3d12.h> doesn't work (or IntelliSense doesn't detect that.)

Am I supposed to include path to Windows 10 SDK manually? I don't have to do this with Windows 8 SDK.


You have to select the target platform in the project propriety window:



I don't have that option in my visual studio (2013 community).


@Dave: ofcourse not.

2 IntelliSense: cannot open source file "d3d12.h" k:\Visual Studio Projects\NT Engine\Application\Application.cpp 2
Error 1 error C1083: Cannot open include file: 'd3d12.h': No such file or directory k:\visual studio projects\nt engine\application\application.cpp 2

I think I'll have to install Visual Studio 2015 (Community). But it's 3 GB only, how come it is supposed to have Windows SDK in it? (cause Windows SDK itself is around 2 GB)
BTW, I am downloading the .iso file and not the installer (vs_community.exe).


Thats because you need VS2015 which can compile for that target. It's only 3GB because the installer for the community edition has a downloaded built into the installer, same as the 2012 and 2013 versions.


The Target OS is something new in 2013 and will probably work the same as selecting your platform toolset even though the higher versions are installed you cannot select them in a lower VS version.

#5244556 Including headers from Windows 10 SDK

Posted by NightCreature83 on 04 August 2015 - 03:09 PM

I had this issue, you have to install Visual Studio 2015 and on the install make sure you got to "custom install" and include all the C++ tools and the Windows SDK bundled with it... For some reason DX12 isn't shipped with the Windows SDK off the Microsoft website.




On mine the d3d12 headers are located at "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\um"


Also the DX12 samples use the D3DX12.h which isn't included in any Windows SDK, you have to get that header from the samples on GitHub https://github.com/Microsoft/DirectX-Graphics-Samples

Thats because since DX11s release D3DX has been deprecated and shouldnt be used, if you want  a replacement for this look at DirectXToolkit at : https://directxtk.codeplex.com/

There are a few functions in the DirectX package that you have to be careful with if you ever want to release to windows store too, one of the ones a lot of people are probably using is D3DCompileFromFile