I do have a problem with loading my vertexes.
When I debug my code. I find out the vertexes are loaded. But when i use render doc, I found out the vertexes are not loaded. Only the first line of my vertex gets loaded. I went thru my code i could not find the problem.
My code:
bool ObjFile(ID3D11Device* device, MeshD3D11* Mesh ,VertexBufferD3D11* vertex, IndexBufferD3D11* IndexBuffer, TextureSrvRtv* SendColorInformation) {
objl::Loader LoadOBJ;
bool ReadingFile = LoadOBJ.LoadFile("ball.obj");
if (!ReadingFile)
{
std::cerr << "the file can't be open" << std::endl;
return false;
}
else
{
//Below is used to get every vertax to mesh objekt. Same metoed is used in the cration of a cube in assigment 2
std::vector<VertaxOBJ> VertaxObjVec;
for (int x = 0; x < LoadOBJ.LoadedVertices.size(); x++)
{
VertaxOBJ VertaxObj;
//Position
VertaxObj.pos.x = LoadOBJ.LoadedVertices[x].Position.X,
VertaxObj.pos.y = LoadOBJ.LoadedVertices[x].Position.Y,
VertaxObj.pos.z = LoadOBJ.LoadedVertices[x].Position.Z;
//Normal
VertaxObj.nor.x = LoadOBJ.LoadedVertices[x].Normal.X,
VertaxObj.nor.y = LoadOBJ.LoadedVertices[x].Normal.Y,
VertaxObj.nor.z = LoadOBJ.LoadedVertices[x].Normal.Z;
//UV
VertaxObj.UV.x = LoadOBJ.LoadedVertices[x].TextureCoordinate.X,
VertaxObj.UV.y = LoadOBJ.LoadedVertices[x].TextureCoordinate.Y;
VertaxObjVec.push_back(VertaxObj);
}
MeshData MeshForVERTAXandINDEXandMESH;
//vertax
MeshForVERTAXandINDEXandMESH.vertexInfo.nrOfVerticesInBuffer = VertaxObjVec.size();
MeshForVERTAXandINDEXandMESH.vertexInfo.sizeOfVertex = sizeof(VertaxObjVec);
MeshForVERTAXandINDEXandMESH.vertexInfo.vertexData = VertaxObjVec.data();
//index
MeshForVERTAXandINDEXandMESH.indexInfo.nrOfIndicesInBuffer = LoadOBJ.LoadedIndices.size();
MeshForVERTAXandINDEXandMESH.indexInfo.indexData = LoadOBJ.LoadedIndices.data();
//mesh
MeshData::SubMeshInfo MeshForMesh;
ColorInformation CI;
SendColorInformation->UploadingTexture(device, 1024, 576, nullptr, DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE);
SendColorInformation->UploadingSRV(device, false, CI.ambient);
SendColorInformation->UploadingTexture(device, 1024, 576, nullptr, DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE);
SendColorInformation->UploadingSRV(device, false, CI.diffuse);
SendColorInformation->UploadingTexture(device, 1024, 576, nullptr, DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE);
SendColorInformation->UploadingSRV(device, false, CI.specular);
MeshForMesh.startIndexValue = 0;
MeshForMesh.nrOfIndicesInSubMesh = 0;
for (int x = 0; x < LoadOBJ.LoadedMeshes.size(); x++) {
//offset tekniskt sätt
MeshForMesh.nrOfIndicesInSubMesh = LoadOBJ.LoadedMeshes[x].Indices.size();
MeshForMesh.ambientTextureSRV = CI.ambient;
MeshForMesh.diffuseTextureSRV = CI.diffuse;
MeshForMesh.specularTextureSRV = CI.specular;
MeshForVERTAXandINDEXandMESH.subMeshInfo.push_back(MeshForMesh);
//the reason the size is in the end. For i need the first element need be zero. For correct caulcation of the startindex
MeshForMesh.startIndexValue += LoadOBJ.LoadedMeshes[x].Indices.size();
}
Mesh->Initialize(device, MeshForVERTAXandINDEXandMESH);
}
return true;
}
The function this file is sent to
void MeshD3D11::Initialize(ID3D11Device* device, const MeshData& meshInfo)
{
vertexBuffer.Initialize(device, meshInfo.vertexInfo.sizeOfVertex,
meshInfo.vertexInfo.nrOfVerticesInBuffer, meshInfo.vertexInfo.vertexData);
indexBuffer.Initialize(device, meshInfo.indexInfo.nrOfIndicesInBuffer,
meshInfo.indexInfo.indexData);
for (int x = 0; x < meshInfo.subMeshInfo.size(); x++)
{
{
SubMeshD3D11 SMD3D11;
SMD3D11.Initialize
(
meshInfo.subMeshInfo[x].startIndexValue,
meshInfo.subMeshInfo[x].nrOfIndicesInSubMesh,
meshInfo.subMeshInfo[x].ambientTextureSRV,
meshInfo.subMeshInfo[x].diffuseTextureSRV,
meshInfo.subMeshInfo[x].specularTextureSRV
);
subMeshes.push_back(SMD3D11);
}
}
}
The render function
#include "AllHeaderFile.h"
void Render(ID3D11DeviceContext* immediateContext, TextureSrvRtv* rtvBackBUffer,
ID3D11DepthStencilView* dsView, D3D11_VIEWPORT& viewport, ShaderD3D11* vshader,
ShaderD3D11* pshader, InputLayoutD3D11* InputLayout, VertexBufferD3D11* vertex,
SamplerD3D11* samplerState, /*ShaderD3D11* cshader,*/
ID3D11UnorderedAccessView* backBufferUAV, ConstantBufferD3D11* ConstantBuffer, CameraD3D11* Cam,
IndexBufferD3D11* IndexBuffer, /*, StructuredBufferD3D11* Structured*/ MeshD3D11* Mesh)
{
float clearColour[4] = { 0, 0, 0, 0 };
immediateContext->ClearRenderTargetView(rtvBackBUffer->GetRTV(), clearColour);
immediateContext->ClearDepthStencilView(dsView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1, 0);
/*UINT stride = sizeof(VertaxOBJ);
UINT offset = 0;*/
//Byt namn på det om det fungerar
ID3D11Buffer* ConstBuffer = ConstantBuffer->GetBuffer();
/*ID3D11Buffer* VertaxBuffer = vertex->GetBuffer();
ID3D11Buffer* Index = IndexBuffer->GetBuffer();*/
ID3D11SamplerState* sampler = samplerState->GetSamplerState();
ID3D11ShaderResourceView* shaderResourceView = rtvBackBUffer->GetSRV();
ID3D11ShaderResourceView* AmbientSRV;
ID3D11ShaderResourceView* DiffuseSRV;
ID3D11ShaderResourceView* SpecularSRV;
ID3D11RenderTargetView* NewRtv = rtvBackBUffer->GetRTV();
Mesh->BindMeshBuffers(immediateContext);
immediateContext->IASetInputLayout(InputLayout->GetInputLayout());
immediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
vshader->BindShader(immediateContext, ShaderType::VERTEX_SHADER);
immediateContext->RSSetViewports(1, &viewport);
pshader->BindShader(immediateContext, ShaderType::PIXEL_SHADER);
immediateContext->OMSetRenderTargets(1, &NewRtv, dsView);
//immediateContext->OMSetRenderTargets(1, &RTVCupemaping, dsView);
immediateContext->VSSetConstantBuffers(0, 1, &ConstBuffer);
immediateContext->PSSetShaderResources(0, 1, &shaderResourceView);
for (int x = 0; x < Mesh->GetNrOfSubMeshes(); x++)
{
AmbientSRV = Mesh->GetAmbientSRV(x);
DiffuseSRV = Mesh->GetDiffuseSRV(x);
SpecularSRV = Mesh->GetSpecularSRV(x);
immediateContext->PSSetShaderResources(1, 1, &AmbientSRV);
immediateContext->PSSetShaderResources(2, 1, &DiffuseSRV);
immediateContext->PSSetShaderResources(3, 1, &SpecularSRV);
Mesh->PerformSubMeshDrawCall(immediateContext, x);
}
immediateContext->PSSetSamplers(0, 1, &sampler);
The struct that i fill data to sent to vertex,index and mesh
struct MeshData
{
struct VertexInfo
{
size_t sizeOfVertex;
size_t nrOfVerticesInBuffer;
void* vertexData;
} vertexInfo;
struct IndexInfo
{
size_t nrOfIndicesInBuffer;
uint32_t* indexData;
} indexInfo;
struct SubMeshInfo
{
size_t startIndexValue;
size_t nrOfIndicesInSubMesh;
ID3D11ShaderResourceView* ambientTextureSRV;
ID3D11ShaderResourceView* diffuseTextureSRV;
ID3D11ShaderResourceView* specularTextureSRV;
};
std::vector<SubMeshInfo> subMeshInfo;
};
```
MeshData
type andobjl
Loader come from? If those are classes that you wrote, then you'll need to share them. \$\endgroup\$