Jump to content
  • Advertisement
Sign in to follow this  
TommyThree

How to pass ComPtrs?

This topic is 604 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

Here is some code

 

FileManager

#ifndef FILEMANAGER_H_
#define FILEMANAGER_H_

#include <string>
#include <list>
#include "Image.h"
#include <wrl.h>


class FileManager
{
public:
	void ImageLoad(std::string path, Microsoft::WRL::ComPtr<ID3D11Device> Device, Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> Texture);
};

#endif
#include "FileManager.h"
#include "WICTextureLoader.h"
#include "Utility.h"

using namespace std;
using namespace DirectX;
using Microsoft::WRL::ComPtr;

void FileManager::ImageLoad(string Path, ComPtr<ID3D11Device> Device, ComPtr<ID3D11ShaderResourceView> Texture)
{
	//Microsoft::WRL::ComPtr<ID3D11Resource> Resource;
	wstring WidePath = StringToWideString(Path);
	CreateWICTextureFromFile(Device.Get(), WidePath.c_str(), nullptr, Texture.ReleaseAndGetAddressOf());
}

GameEngine

#ifndef GAMEENGINE_H_
#define GAMEENGINE_H_

#include "BaseDx.h"
#include "FileManager.h"
#include "GuiManager.h"

class GameEngine
{
public:
	BaseDx* GetDirectX();
	void LoadContent();
	void Update();
	void Draw();
	void TimeTick();
	FileManager AFileManager;
private:
	BaseDx DirectX11;
};

#endif
#include "GameEngine.h"


BaseDx* GameEngine::GetDirectX()
{
	return &DirectX11;
}

void GameEngine::LoadContent()
{
	AFileManager.ImageLoad("images\box.bmp", GetDirectX()->GetDevice(), GetDirectX()->GetTexture() );
}

void GameEngine::Update()
{

}

void GameEngine::Draw()
{

}

void GameEngine::TimeTick()
{

}

BaseDx

#ifndef BASEDX_H_
#define BASEDX_H_


#include <string>
#include <wrl.h>
#include "Effects.h"


class BaseDx
{
public:
	void InitializeDirectX(HWND MainWindow, int Width, int Height);
	const Microsoft::WRL::ComPtr<ID3D11Device> & GetDevice();
	const Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> & GetTexture();
private:
	Microsoft::WRL::ComPtr<ID3D11Device> Device;
	Microsoft::WRL::ComPtr<ID3D11DeviceContext> DeviceContext;
	Microsoft::WRL::ComPtr<IDXGISwapChain> SwapChain;
	Microsoft::WRL::ComPtr<ID3D11RenderTargetView> RenderTargetView;
	Microsoft::WRL::ComPtr<ID3D11DepthStencilView> DepthStencilView;
	Microsoft::WRL::ComPtr<ID3D11Texture2D> DepthStencilBuffer;
	//Microsoft::WRL::ComPtr<ID3D11InputLayout> input_layout;
	Microsoft::WRL::ComPtr<ID3D11VertexShader> VertexShader;
	Microsoft::WRL::ComPtr<ID3D11PixelShader> PixelShader;
	Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> Texture;
	Microsoft::WRL::ComPtr<ID3D11RasterizerState> RasterizerState;
};

#endif // !BASEDX_H_


Snippet from BaseDx.cpp

const Microsoft::WRL::ComPtr<ID3D11Device> & BaseDx::GetDevice()
{
	return Device;
}

const Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> & BaseDx::GetTexture()
{
	return Texture;
}

When I try to run this code, I get errors in filemanager.h that says:

 

 
Error C2065 'ID3D11Device': undeclared identifier
Error C2065 'ID3D11ShaderResourceView': undeclared identifier
Error C2923 'Microsoft::WRL::ComPtr': 'ID3D11Device' is not a valid template type argument for parameter 'T'
Error C2923 'Microsoft::WRL::ComPtr': 'ID3D11ShaderResourceView' is not a valid template type argument for parameter 'T'
 
Also in filemanager.cpp, I get 1 error that says:
 
Error C2511 'void FileManager::ImageLoad(std::string,Microsoft::WRL::ComPtr<ID3D11Device> &,Microsoft::WRL::ComPtr<ID3D11ShaderResourceView>)': overloaded member function not found in 'FileManager'
 
 
 
I din't understand why I'm getting these errors. Can someone help? This is my 1st time trying to put together a object oriented game engine or using com pointers. I need to pass the comptrs because CreateWICTextureFromFile needs a Device and Texture2D objects.
Edited by TommyThree

Share this post


Link to post
Share on other sites
Advertisement

But technically you don't wanna pass ComPtr's:

- If you pass them by value you will pay for the ref counting when it isn't necessary(you don't do this, but just for the record).

- If you pass them by ref you type more and you risk to forget making it a ref.

So I pass always by raw ptr.

Edited by imoogiBG

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!