Click here to Skip to main content
15,884,926 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: basic MFC app Pin
Calin Negru8-Apr-20 23:38
Calin Negru8-Apr-20 23:38 
GeneralRe: basic MFC app Pin
Victor Nijegorodov9-Apr-20 0:06
Victor Nijegorodov9-Apr-20 0:06 
GeneralRe: basic MFC app Pin
Calin Negru9-Apr-20 0:28
Calin Negru9-Apr-20 0:28 
Questionplease help me find the error guys, they said expected unqualified-id before '{' token at line 11, col 19.. Pin
Salsabilatikah Yunus5-Apr-20 9:08
Salsabilatikah Yunus5-Apr-20 9:08 
AnswerRe: please help me find the error guys, they said expected unqualified-id before '{' token at line 11, col 19.. Pin
Victor Nijegorodov5-Apr-20 9:15
Victor Nijegorodov5-Apr-20 9:15 
AnswerRe: please help me find the error guys, they said expected unqualified-id before '{' token at line 11, col 19.. Pin
k50545-Apr-20 9:27
mvek50545-Apr-20 9:27 
QuestionRe: please help me find the error guys, they said expected unqualified-id before '{' token at line 11, col 19.. Pin
David Crow6-Apr-20 4:03
David Crow6-Apr-20 4:03 
Question[SOLVED]Problems when trying to abstract D3D11 types in a class with C++ Pin
txesmi4-Apr-20 0:07
txesmi4-Apr-20 0:07 
Hi all,
I am a hobbyist developer and I am recycling myself with the intention of learning C++ and D3D11. To give you an idea, I have been using for more than a decade a D3D9 engine with a programming language very similar to C. After doing several D3D11 tutorials, I think I understand fairly well where the shots are going.

The thing is that these tutorials lack an architecture designed to be scaled and they all end up in a function that does everything at once. Reading around, I have found a small explanation of how to combine in a simple way all the buffers that have to be associated to the pipeline to end up drawing on the screen, but I can't make it work.

The system is based on a class called 'Bindable' that contains a virtual function to associate the buffers to the pipeline and that is configured to be 'friendly' to the class that initializes the graphics (Graphics) to be able to access its private members.
C++
class Bindable {
public:
    virtual void Bind(Graphics& _gfx) noexcept = 0;
    virtual ~Bindable() = default;
protected:
    static ID3D11DeviceContext* GetContext(Graphics& _gfx) noexcept;
    static ID3D11Device* GetDevice(Graphics& _gfx) noexcept;
};

I expand this class for each type of buffer with its specific constructor and dinder. For example, the mesh index buffer, which contains a pointer to the buffer and the number of indexes, looks like this:
C++
class IndexBuffer : public Bindable {
public:
    IndexBuffer(Graphics& _gfx, const std::vector<unsigned short>& _indices);
    void Bind(Graphics& _gfx) noexcept override;
    UINT GetCount() const noexcept;
private:
    UINT m_count;
    Microsoft::WRL::ComPtr<ID3D11Buffer> mp_buffer;
};

The implementation is very simple:
C++
IndexBuffer::IndexBuffer(Graphics& _gfx, const std::vector<unsigned short>& _indices)
     :
     m_count((UINT)_indices.size())
{
     D3D11_BUFFER_DESC _ibd = {};
     _ibd.BindFlags = D3D11_BIND_INDEX_BUFFER;
     _ibd.Usage = D3D11_USAGE_DEFAULT;
     _ibd.CPUAccessFlags = 0u;
     _ibd.MiscFlags = 0u;
     _ibd.ByteWidth = UINT(m_count * sizeof(unsigned short));
     _ibd.StructureByteStride = sizeof(unsigned short);

     D3D11_SUBRESOURCE_DATA _isd = {};
     _isd.pSysMem = _indices.data();

     GetDevice(_gfx)->CreateBuffer(
         &_ibd,
         &_isd,
         &mp_buffer
     )
 }

 void IndexBuffer::Bind(Graphics& _gfx) noexcept {
     GetContext(_gfx)->IASetIndexBuffer(
         mp_buffer.Get(),
         DXGI_FORMAT_R16_UINT,
         0u
     );
 }

 UINT IndexBuffer::GetCount() const noexcept {
     return m_count;
 }

In the class that manages the initialization of D3D11, a function includes the instances of the DirectX buffer classes in a vector and returns their index in the list.
C++
std::vector<std::unique_ptr<Bindable>> m_binds;
...

UINT Graphics::AddBind(std::unique_ptr<Bindable> _bind) noexcept(!IS_DEBUG) {
    m_binds.push_back(std::move(_bind));
    return m_binds.size() - 1;
}

As a test method, I create instances of the 'Bindable' heir classes and save their index in order to associate their buffers in subsequent frames. All in the same function, by the moment.
C++
if (m_ibufIndex < 0)
    m_ibufIndex = AddBind(std::make_unique<IndexBuffer>(*this, _indices));
else
    m_binds[m_ibufIndex].get()->Bind(*this);

This way, I intend to be able to associate all the buffers for each actor in the scene by means of a list of indexes and thus also be able to reuse the same buffers in different actors, although I haven't written this part yet, as I have found that the buffers are not associated to the pipeline correctly. When I call 'ID3D11DeviceContext::DrawIndexed' I get a warning that says the following:
Quote:
ID3D11DeviceContext::DrawIndexed: An Index Buffer is expected, but none is bound. This is OK, as reading from a missing Index Buffer is defined to return 0. However the developer probably did not intend to make use of this behavior.

The thing is that the code compiles without problems and I have been able to verify, with the invaluable help of ImGui, that the instances of 'Bindable' are certainly created and that the buffers exist. For this purpose, I have added a member to the 'IndexBuffer' class that returns the description of the buffer and that I check right after the 'Bindable' creation/association block and it certainly exists.

I have tried to reinterpret the pointers hosted in 'm_binds' to their corresponding class, although I am pretty sure that it is not necessary.
C++
((IndexBuffer*)(m_binds[m_ibufIndex].get()))->Bind(*this);

Does anyone have any idea what might keep buffers from being associated with the pipeline?

If someone could shed some light on the matter I'd be very grateful.

Greetings and thank you for your time,
txes

modified 4-Apr-20 11:00am.

AnswerRe: Problems when trying to abstract D3D11 types in a class with C++ Pin
Graham Breach4-Apr-20 1:47
Graham Breach4-Apr-20 1:47 
GeneralRe: Problems when trying to abstract D3D11 types in a class with C++ Pin
txesmi4-Apr-20 3:11
txesmi4-Apr-20 3:11 
GeneralRe: Problems when trying to abstract D3D11 types in a class with C++ Pin
Graham Breach4-Apr-20 4:16
Graham Breach4-Apr-20 4:16 
GeneralRe: Problems when trying to abstract D3D11 types in a class with C++ Pin
txesmi4-Apr-20 4:54
txesmi4-Apr-20 4:54 
QuestionFacial Recognition in C++, from scratch Pin
Ana Gheorghiță3-Apr-20 0:58
Ana Gheorghiță3-Apr-20 0:58 
AnswerRe: Facial Recognition in C++, from scratch Pin
Richard MacCutchan3-Apr-20 1:59
mveRichard MacCutchan3-Apr-20 1:59 
AnswerRe: Facial Recognition in C++, from scratch Pin
_Flaviu5-Apr-20 0:42
_Flaviu5-Apr-20 0:42 
Questioninverse sinus, floats Pin
Calin Negru2-Apr-20 21:25
Calin Negru2-Apr-20 21:25 
AnswerRe: inverse sinus, floats Pin
Richard MacCutchan2-Apr-20 21:35
mveRichard MacCutchan2-Apr-20 21:35 
GeneralRe: inverse sinus, floats Pin
Calin Negru2-Apr-20 21:53
Calin Negru2-Apr-20 21:53 
AnswerRe: inverse sinus, floats Pin
CPallini2-Apr-20 21:57
mveCPallini2-Apr-20 21:57 
GeneralRe: inverse sinus, floats Pin
Calin Negru2-Apr-20 23:01
Calin Negru2-Apr-20 23:01 
GeneralRe: inverse sinus, floats Pin
CPallini2-Apr-20 23:18
mveCPallini2-Apr-20 23:18 
GeneralRe: inverse sinus, floats Pin
Calin Negru2-Apr-20 23:36
Calin Negru2-Apr-20 23:36 
GeneralRe: inverse sinus, floats Pin
CPallini3-Apr-20 2:17
mveCPallini3-Apr-20 2:17 
GeneralRe: inverse sinus, floats Pin
Victor Nijegorodov2-Apr-20 23:39
Victor Nijegorodov2-Apr-20 23:39 
GeneralRe: inverse sinus, floats Pin
Calin Negru3-Apr-20 0:02
Calin Negru3-Apr-20 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.