Jump to content
  • Advertisement
Sign in to follow this  
Trillian

DirectX naming conventions

This topic is 4791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm creating my own D3D library and I want to know somthing. Why does all the D3D things are interfaces? for exemple: -ID3DXMesh -IDirect3DVertexBuffer9 -etc I was reading a C# book recently (But i program in C++) and I felt on a page saying that interfaces were classes with only virtual member functions. If that's the case then we shouldn't be able to use these functions. example: IDirect3DVertexBuffer9::Unlock(); Because they were made to be defined in another class that inherits this interface... Could you please tell me what this is all about cause I want to have a similar naming convention in my library. My guesses: - __interface (which is how the IDirect3DVertexBuffer9 and others are declared) is not a true interface. - C++ interfaces have a different meaning than C# ones

Share this post


Link to post
Share on other sites
Advertisement
If you have a pointer of an interface type, this pointer will always point to an instance of a class implementing said interface. IE:


class IBlah
{
public:
virtual void Bleh() = 0;
};

class ConcreteBlah : public IBlah
{
virtual void Bleh()
{
cout << "Bleh world" << endl;
}
};

// ...

IBLah* myBlah;

// ...


// you do this:
myBlah = new ConcreteBlah();


// but this is not allowed, since you cannot instantiate a class with
// one or more pure virtuals (the =0 part):
myBlah = new IBlah() ; //


The reason why DirectX uses interfaces for everything comes from the fact that it is based on COM. In COM, all functionality is accessed through interfaces. A pointer to concrete implementations of those interfaces is usually obtained through a class factory (traditional COM), through the CoCreateInstance() function or through various *Create() functions (very common in DX). Methods on COM objects can also return new instances of coclasses (a class implementing one or more COM interaces).

Share this post


Link to post
Share on other sites
They are interface, same as C# or Java and every object model. That's why you cannot instance a IDirect3D object for exemple. DirectX must contains code with classes implenting those interfaces. However, you never have direct access to them, and it is a good thing, since you shouldn't be able to construct or destroy yourself DirectX classes. DirectX creates them for you through its functions, and return them as a pointer to an interface. Odd but nice way to do things, imho.

Share this post


Link to post
Share on other sites
...And that explains why they made the LP things (like LPDIRECT3DTEXTURE9), beacause as it can only be used as a pointer which will be filled with an unknown dx class, you can't instanciate as a IDirect3DTexture9 alone.

Writing this:
IDirect3DTexture9 bob;

Would get you the error:
error C2259: 'IDirect3DTexture9' : cannot instantiate abstract class

Ok now thats really clear!

PS: I'm writing this more for myself than to you but anyways

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!