Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / DarkGDK Object Masking class functions - mimicks dbpro set object mask

Author
Message
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 31st Jul 2009 12:22 Edited at: 31st Jul 2009 12:26
Hello All

I have been working a bit lately on some shader related things, and have had to work around a number of small limitation that are part of DarkGDK, mainly in the form of missing commands(missing in the context that they are a part of DarkBasic Pro and not DarkGDK).

One of the most handy features of DarkBasic Pro, when you are using shaders, or rendering with multiple cameras in any way, is the ability to mask an object, through the object itself.

In DarkGDK, we also have the ability, although it requires that we exclude and include objects, based on syncmasking cameras, to try and maintain some semblance of performance, and that gets to be difficult to manage when you have many render passes and many cameras(as I found out in a recent project, that I am still working on).

To that end, I dedicded to write up a small class to handle getting at and altering the DarkGDK object's internals flags(which are the same as DarkBasic Pro, as we use the same DBOData format, so the masking ability is there in the object, just no command in GDK to access it) for masking. The result is the following software, which enables you to set, restore and maintain DarkGDK 3D object's masking values.

Setting an object's masking value for example, to (1<<1), will result in that object ONLY rendering to camera 1 and nothing else.

The software contains some documentation in a readme file and in the header of the class.

I would really appreciate if anybody with some spare time and at least a small interest could do a little testing with it, play around and see if it doesnt crap out under certain circumstances.
I've done a fair bit of testing, and it has been working for my purposes without any problems, but I havent done anything stressful to it. The Class tracks objects and their mask values by reading the values directly from the GDK object and storing it into a vector of struct objects that contain object info.

Anyway, the attached .ZIP file(around 280k zipped) contains a compiled and working .EXE file, no media required, to demonstrate the functions and how they work. It also contains the complete source code for the class, and its singleton header(which is based off widely known singleton methods). The Main.cpp source code file is heavily commented and explains the usage of all of the commands within it.

If it turns out this is something that people can use and find handy, ill consider sticking it into the WIP or Program Announcement threads, I stuck it here as I thought being DarkGDK related and not fully tested, this is the best place for it.

Here are some screenshots of the demo program running :

Rotating cube when program initially starts


Masking all but Camera 1 and 3 :


Masking all but Camera 2 :


All input is appreciated, cheers

EDIT : I shoud have mentioned that the EXE is compiled with DarkGDK 7.3

If it ain't broke.... DONT FIX IT !!!

Attachments

Login to view attachments
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 31st Jul 2009 12:31
Here is the source code in tags incase you have trouble downloading from this site :

Main.cpp :


pwSingleton.h :


MaskObject.h :


MaskObject.cpp :


Hope this helps someone

If it ain't broke.... DONT FIX IT !!!
prasoc
15
Years of Service
User Offline
Joined: 8th Oct 2008
Location:
Posted: 31st Jul 2009 13:53
It is a very useful class (I will probably use it when I have multiplayer with 2 cameras to hide the other person's gun and make a box that only a certain character can see), You managed to trump TGC in making their own commands lol


Your signature has been erased by a mod
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 31st Jul 2009 15:19 Edited at: 31st Jul 2009 15:20
Why not just make the vector as big as your highest object in the list and directly relate object IDs to indices and not resize it? Your current method reeks of inefficiency with a long list. You could maybe use a map to lower the search rate, but still. I'm also not sure exactly sure why you'd ever want to record your old mask and revert it. Lastly, your 'singleton' isn't a singleton at all, this line:



shows you can create as many instances as you want.

Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 31st Jul 2009 15:27 Edited at: 31st Jul 2009 16:04
picky picky

I never said it was efficient... it demonstrates a technique in what is an easy to understand manner.... and ill check my singleton implementation, looks like I may have made an error in declaring the constructor public.

I agree though, there are many other ways, some more efficient, some less so. This is the one I chose to demonstrate this.

EDIT : checked the singleton... seems I did hose it somewhere along the line lol, it isnt important though for the purpose of what this is doing. If this turns out to be useful aswell, constructive comments on improving the efficiency are welcome

If it ain't broke.... DONT FIX IT !!!
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 31st Jul 2009 16:18
After thinking about efficiency a little(cheers dark coder for putting my mind on that subject) I decided that I would post a function to set an object's mask value as simlpy as is possible, with as little overhead as possible.

Here it is for anybody that doesnt want to use the class :



It will return TRUE if it sets the mask value to what you pass it, it will return FALSE if the object doesnt exist. It has no error checking for mask values, just checks if the object exists before attempting to access it with a pointer.

You can either put this entire block at the top of you program and call it, or you can put a forward decleration of it at the start of your project/global header and define it wherever.

You will notice if you play with the pointer that you get from dbGetObject, that there are quite a few things you can alter with GDK objects, from simple things like this, through to directly accessing the directx shaders and mesh in the object.

If it ain't broke.... DONT FIX IT !!!

Login to post a reply

Server time is: 2024-10-01 08:39:49
Your offset time is: 2024-10-01 08:39:49