Exclude DatablockMember from Shader Memcpy?

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Exclude DatablockMember from Shader Memcpy?

Post by white_waluigi »

I'm currently creating a LightDatablock to Hold shader paramters for LigthMaterials.
But right now I have Debug Information in that Datablock (Id of the refernced Light) that I don't want to be send to the Shader.
But since the whole thing is getting memcpy'd it seams impossible to avoid.
So is there a way to exclude it from the memcopy or do I have to solve this another way?

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4208
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 802
Contact:

Re: Exclude DatablockMember from Shader Memcpy?

Post by dark_sylinc »

I do not understand. YOU are in control of what gets memcpy'd.

uploadToConstBuffer is a pure virtual call. The HlmsPbsDatablock::uploadToConstBuffer decides to use memcpy. But you don't have to.

Example:

Code: Select all

void LightDatablock::uploadToConstBuffer( char *dstPtr )
{
    float * RESTRICT_ALIAS asFloat = *dstPtr;
    asFloat[0] = 1.0f; //Always send a constant
    //Leave asFloat[1] uninitialized
    asFloat[2] = this->mMyVariable;

    //Write after asFloat[2]. COMPLETELY OPTIONAL
    memcpy( dstPtr + sizeof(float)*3, &this->startOfVarsIWantToCopy, sizeBytes );

    //Write more data
    asFloat[25] = this->mMyOtherVariable;
}
Ogre doesn't memcpy for you. It's the overriden function that may use memcpy. Ogre's default implementations use memcpy because it's fast and convenient. But you're not forced to do that. :)

In fact the HlmsPbsDatablock has a lot of information that is not being sent to the shaders (like the UV source variables, the blending modes, the fresnel mode, the std::vector holding the textures, etc). It's only memcpy'ing a tiny portion that is needed by the shaders as a buffer.

white_waluigi
Goblin
Posts: 253
Joined: Sat Sep 28, 2013 3:46 pm
x 10

Re: Exclude DatablockMember from Shader Memcpy?

Post by white_waluigi »

Thanks a lot, I probably should have looked at the code more, sorry about that

Post Reply