C++/Cx can't define vertex struct in DirectXBase class, could do it in child classes

StackOverflow https://stackoverflow.com/questions/19437380

  •  01-07-2022
  •  | 
  •  

سؤال

Here is my DirectXBase class header:

#pragma once

#include "pch.h"

struct Vertex
{   
XMFLOAT3 pos;
XMFLOAT3 color;
};

struct ModelViewProjectionConstantBuffer
{
DirectX::XMFLOAT4X4 model;
DirectX::XMFLOAT4X4 view;
DirectX::XMFLOAT4X4 projection;
};

ref class DirectXBase abstract
{
internal:
DirectXBase();

virtual void Initialize(
    Windows::UI::Core::CoreWindow^ window,
    Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ swapChainPanel,
    float dpi);

virtual void HandleDeviceLost();
virtual void CreateDeviceIndependentResources();
virtual void CreateDeviceResources();
virtual void SetDpi(float dpi);
virtual void UpdateForWindowSizeChanged();
virtual void CreateWindowSizeDependentResources();
virtual void Render() = 0;
virtual void Present();
void ValidateDevice();  
virtual float ConvertDipsToPixels(float dips);

protected private:
Windows::UI::Core::CoreWindow^ m_window;
Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ m_swapChainPanel;

// Transforms used for display orientation.
D2D1::Matrix3x2F                                m_rotationTransform2D;
DirectX::XMFLOAT4X4                             m_rotationTransform3D;
DXGI_MODE_ROTATION ComputeDisplayRotation();

//Directx Core Objects
Microsoft::WRL::ComPtr<ID3D11Device1>           m_d3dDevice;
Microsoft::WRL::ComPtr<ID3D11DeviceContext1>    m_d3dContext;
Microsoft::WRL::ComPtr<IDXGISwapChain1>         m_swapChain;
Microsoft::WRL::ComPtr<ID3D11RenderTargetView>  m_d3dRenderTargetView;

// Cached renderer properties.
D3D_FEATURE_LEVEL                               m_featureLevel;
Windows::Foundation::Size                       m_renderTargetSize;
Windows::Foundation::Rect                       m_windowBounds;
float                                           m_dpi;
Windows::Graphics::Display::DisplayOrientations m_orientation;
bool                                            m_stereoEnabled;

// Direct3D Rendering Objects. Required for 3D.
Microsoft::WRL::ComPtr<ID3D11DepthStencilView>  m_d3dDepthStencilView;

// Transform used for display orientation.
DirectX::XMFLOAT4X4 m_orientationTransform3D;
};

I get the following error message:

syntax error : missing ';' before identifier 'pos'

I have no idea why it's not recognizing my struct. The funny thing is, I just copied it and pasted it from the header of a CubeRenderer class that inherits from this one so that I can have access to these structs from any inheriting class...the code ran as copied about five minutes ago.

In case it's helpful, here are my two child class headers with the structs moved to those headers, which compiles and runs fine.

CubeRenderer.h:

#pragma once

#include "DirectXBase.h"
#include <DirectXMath.h>

using namespace DirectX;

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

struct CubeVertex
{   
XMFLOAT3 pos;
XMFLOAT3 color;
};

struct CubeMVPBuffer
{
DirectX::XMFLOAT4X4 model;
DirectX::XMFLOAT4X4 view;
DirectX::XMFLOAT4X4 projection;
};

ref class CubeRenderer : public DirectXBase
{
internal:
CubeRenderer();

virtual void CreateDeviceResources() override;
virtual void CreateWindowSizeDependentResources() override;
virtual void Render() override;
void Update(float timeTotal, float timeDelta);
private:
bool m_loadingComplete;

Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;

uint32 m_indexCount;
CubeMVPBuffer m_constantBufferData;
};

HillRenderer.h:

#pragma once

#include "DirectXBase.h"
#include <DirectXMath.h>

using namespace DirectX;

#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

struct HillVertex
{   
    XMFLOAT3 pos;
    XMFLOAT3 color;
};

struct HillMVPBuffer
{
    DirectX::XMFLOAT4X4 model;
    DirectX::XMFLOAT4X4 view;
    DirectX::XMFLOAT4X4 projection;
};

ref class HillRenderer : public DirectXBase
{
internal:
    HillRenderer();

    virtual void CreateDeviceResources() override;
    virtual void CreateWindowSizeDependentResources() override;
    virtual void Render() override;
    void Update(float timeTotal, float timeDelta);
private:
    bool m_loadingComplete;

    Microsoft::WRL::ComPtr<ID3D11InputLayout> m_inputLayout;
    Microsoft::WRL::ComPtr<ID3D11Buffer> m_vertexBuffer;
    Microsoft::WRL::ComPtr<ID3D11Buffer> m_indexBuffer;
    Microsoft::WRL::ComPtr<ID3D11VertexShader> m_vertexShader;
    Microsoft::WRL::ComPtr<ID3D11PixelShader> m_pixelShader;
    Microsoft::WRL::ComPtr<ID3D11Buffer> m_constantBuffer;

    uint32 m_indexCount;
    HillMVPBuffer m_constantBufferData;

    float GetHeight(float x, float z) const
    {
        return 0.3f*(z*sinf(0.1f*x) + x*cosf(0.1f*z));
    }
};
هل كانت مفيدة؟

المحلول

Your struct type doesn't "work" is because when you declare that struct, compiler doesn't know (yet) what XMFLOAT3 means.

Before you can use XMFLOAT3 type, it has to be declared somewhere. My guess is it is declared within DirectXMath.h #include DirectXMath.h at the beginning of DirectXBase.h, and it should work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top