晚上好,
我正在尝试将XMFLOAT3X3发送到常量缓冲区(请参阅下面的代码).
ZeroMemory(&constDesc, sizeof(constDesc));
constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constDesc.ByteWidth = sizeof(XMFLOAT3X3);
constDesc.Usage = D3D11_USAGE_DEFAULT;
result = m_pDevice->CreateBuffer(&constDesc,0,&m_pTexTransformCB);
if (FAILED(result)) {
MessageBoxA(NULL,"Error creating constant buffer m_pTexTransformCB", "Error", MB_OK);
return false;
}
Run Code Online (Sandbox Code Playgroud)
但编译器告诉我XMFLOAT3X3是常量缓冲区字节宽度的无效维度:
D3D11: ERROR: ID3D11Device::CreateBuffer: The Dimensions are invalid. For ConstantBuffers, marked with the D3D11_BIND_CONSTANT_BUFFER BindFlag, the ByteWidth (value = 36) must be a multiple of 16 and be less than or equal to 65536. [ STATE_CREATION ERROR #66: CREATEBUFFER_INVALIDDIMENSIONS ]
Run Code Online (Sandbox Code Playgroud)
但是,我对HLSL并不熟悉,所以我不确定是否将字节宽度设置为48,着色器的cbuffer中的float3x3将正确注册.我该怎样处理这个最好的?
如果您需要更多信息,请发表评论,我将编辑问题.我希望它足够清楚.
我有一个具有以下签名的函数:
float* Interpolate(float t, UINT iOrder, UINT iDimension, float** ppPointsArray);
Run Code Online (Sandbox Code Playgroud)
尝试按如下方式调用时:
float ppfValues[2][1];
ppfValues[0][0] = 0.0f;
ppfValues[1][0] = 10.0f;
float* pfResult = MyMathFuncs::Interpolate(0.5f,2,1,ppfValues);
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error: argument of type float(*)[1] is incompatible with parameter of type "float**"
Run Code Online (Sandbox Code Playgroud)
如果我想正确地调用它,我应该这样做:
float** ppfValues = new float*[2];
ppfValues[0] = new float(0.0f);
ppfValues[1] = new float(10.0f);
float* pfResult = MyMathFuncs::Interpolate(0.5f,2,1,ppfValues);
Run Code Online (Sandbox Code Playgroud)
现在的问题是:我认为float [x] [y]实际上与浮点数相同**为什么不是?技术原因是什么?那么它们究竟是什么呢?
我打算用C++编写一个游戏,它将是CPU密集型的(寻路,遗传算法,神经网络......)所以我一直在考虑如何最好地解决这种情况,以便它能运行顺利.
(让这个问题的上半部分是附带信息,我不希望它限制主要问题,但如果你能给我旁注,那将会很好)
是否值得学习如何使用ASM,因此我可以用C++进行ASM调用,它能给我一个显着/显着的性能优势吗?
我应该在什么情况下使用它?
我不确定我做错了什么,我认为所有内容都只定义了一次,所有内容都正确关联,但我想情况并非如此......
这是我的编译器给我的错误:
1>StaticElements.obj : error LNK2001: unresolved external symbol "private: static int Powerup_Health::g_refCount" (?g_refCount@Powerup_Health@@0HA)
1>StaticElements.obj : error LNK2001: unresolved external symbol "private: static class DBModel * Powerup_Health::g_pModel" (?g_pModel@Powerup_Health@@0PAVDBModel@@A)
1>StaticElements.obj : error LNK2001: unresolved external symbol "private: static int Powerup_QuadDamage::g_refCount" (?g_refCount@Powerup_QuadDamage@@0HA)
1>StaticElements.obj : error LNK2001: unresolved external symbol "private: static class DBModel * Powerup_QuadDamage::g_pModel" (?g_pModel@Powerup_QuadDamage@@0PAVDBModel@@A)
Run Code Online (Sandbox Code Playgroud)
码:
StaticElements.h
#pragma once
#include "D3DUtil.h"
class ContentManager;
class Level;
class GraphCamera;
class Powerup_Health;
class Powerup_QuadDamage;
class StaticElements
{
public:
StaticElements(){};
~StaticElements(){};
void PreLevelInitialisation(Level* pLevel);
void …Run Code Online (Sandbox Code Playgroud) 是否可以在类定义中创建类的对象而不使用默认构造函数?
class Vector3D {
public:
Vector3D(int x, int y, int z);
virtual ~Vector3D();
private:
int m_X;
int m_y;
int m_z;
};
class CustomClass {
private:
Vector3D m_Vec(50,50,50); //error
};
Run Code Online (Sandbox Code Playgroud) 我试图找出这段代码的作用:
std::vector<std::vector<bool> > visited(rows, std::vector<bool>(cols, 0));
Run Code Online (Sandbox Code Playgroud)
'rows'和'cols'都是整数.
它调用构造函数,但我不确定如何.这是我从一些项目得到的示例代码......
它还给了我以下警告:
c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(2140): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\vector(2126) : see reference to function template instantiation 'void std::vector<_Ty,_Ax>::_BConstruct<_Iter>(_Iter,_Iter,std::_Int_iterator_tag)' being compiled
1> with
1> [
1> _Ty=bool,
1> _Ax=std::allocator<bool>,
1> _Iter=int
1> ]
1> c:\ai challenge\code\project\project\state.cpp(85) : see reference to function template instantiation 'std::vector<_Ty,_Ax>::vector<int>(_Iter,_Iter)' being compiled
1> with
1> [
1> _Ty=bool,
1> _Ax=std::allocator<bool>,
1> …Run Code Online (Sandbox Code Playgroud) 我的代码在调试模式下运行良好但在发布模式下失败.
这是我的代码片段,它失败了:
LOADER->AllocBundle(&m_InitialContent);
while(!m_InitialContent.isReady())
{
this->LoadingScreen();
}
Run Code Online (Sandbox Code Playgroud)
AllocBundle()将加载m_InitialContent中包含的内容,并在完成后将其准备状态设置为true.这是使用多线程实现的.
this->LoadingScreen() 应该渲染一个加载屏幕,但是当时还没有实现,所以该函数有一个空体.
显然这可能是错误的原因:如果我给函数LoadingScreen()一行代码:std::cout<<"Loading"<<std::endl;那么它将运行正常.
如果我不这样做,那么代码就会陷入困境while(!m_InitialContent.isReady())它甚至不会跳转到方括号(this->LoadingScreen();)之间的代码.显然它也没有更新while语句中的表达式,因为它永远停留在那里.
有没有人有任何想法可能导致这个?如果是这样,问题可能是什么?我完全不解.
编辑:请求附加代码
ContentLoader的成员: details::ContentBundleAllocator m_CBA;
void ContentLoader::AllocBundle(ContentBundle* pBundle)
{
ASSERT(!(m_CBA.isRunning()), "ContentBundleAllocator is still busy");
m_CBA.Alloc(pBundle, m_SystemInfo.dwNumberOfProcessors);
}
void details::ContentBundleAllocator::Alloc(ContentBundle* pCB, UINT numThreads)
{
m_bIsRunning = true;
m_pCB = pCB;
pCB->m_bIsReady = false;
m_NumRunningThrds = numThreads;
std::pair<UINT,HANDLE> p;
for (UINT i = 0; i < numThreads; ++i)
{
p.second = (HANDLE)_beginthreadex(NULL,
NULL,
&details::ContentBundleAllocator::AllocBundle,
this,
NULL,&p.first);
SetThreadPriority(p.second,THREAD_PRIORITY_HIGHEST);
m_Threads.Insert(p);
}
}
unsigned int __stdcall details::ContentBundleAllocator::AllocBundle(void* …Run Code Online (Sandbox Code Playgroud) 我正在使用DirectX在visual studio中工作,今天我遇到了一些奇怪的编译器错误(对我来说没有任何意义)......
这些是我得到的错误:
错误C2143:语法错误:缺少';' 在'.'之前 错误C2059:语法错误:')'
我已经仔细检查了我的代码并且没有发现任何错别字/错误(我可能错了......)
我希望有人可以告诉我错误通常意味着什么以及在哪里看...
我会在下面放一些代码,指出发生错误的行(如果你想检查的话)
额外信息:m_ImTexture2D是一个成员结构.Vertex.PosTex是结构中的结构
GameManager.cpp:
(231): error C2143: syntax error : missing ';' before '.'
(231): error C2143: syntax error : missing ';' before '.'
(232): error C2143: syntax error : missing ';' before '{'
(233): error C2143: syntax error : missing ';' before '}'
(233): error C2143: syntax error : missing ';' before ','
(234): error C2143: syntax error : missing ';' before '{'
(234): error C2143: syntax error : missing ';' before …Run Code Online (Sandbox Code Playgroud) c++ compiler-construction directx compiler-errors visual-studio-2010
c++ ×8
assembly ×1
constructor ×1
direct3d ×1
direct3d11 ×1
directx ×1
hlsl ×1
performance ×1
pointers ×1
release-mode ×1
shader ×1
vector ×1