NLS Engine  v0.1
The Next Logical Step in game engine design.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines
RenderModuleFactories.cpp
Go to the documentation of this file.
00001 
00012 #include <d3d9.h>
00013 #include <Dxerr.h>
00014 
00015 #include "RenderModule.h"
00016 #include "../sharedbase/EventLogger.h"
00017 
00018 namespace GraphicsCore {
00019   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00020   HRESULT RenderModule::TextureFactory(const std::string& file, LPDIRECT3DTEXTURE9 *texture) {
00021     if (this->pd3dDevice == NULL) {
00022       LOG(LOG_PRIORITY::ERR, "Cannot load texture from file '" + file + "' because the DirectX device was not activated.");
00023       return -1;
00024     }
00025     
00026     HRESULT hr;
00027     
00028     // Load texture from designated file string
00029     hr = D3DXCreateTextureFromFileEx(this->pd3dDevice, //Our D3D Device
00030         file.c_str(), //Filename of our texture
00031         D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file
00032         D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
00033         1, //MipLevels
00034         0, //Usage, Is this to be used as a Render Target? 0 == No
00035         D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
00036         D3DPOOL_MANAGED, //Pool, let D3D Manage our memory
00037         D3DX_DEFAULT, //Filter:Default filtering
00038         D3DX_DEFAULT, //MipFilter, used for filtering mipmaps
00039         0, //Disable ColourKey
00040         NULL, //SourceInfo, returns extra info if we want it (we don't)
00041         NULL, //Palette:We're not using one
00042         texture // Our texture goes here.
00043         );
00044     
00045     if (FAILED(hr)) {
00046       LOG(LOG_PRIORITY::MISSRESS, "Failed to load texture from file: " + file);
00047     }
00048     
00049     return hr;
00050   }
00051 
00052   /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00053   HRESULT RenderModule::MeshFactory(const std::string& file, DWORD options, LPD3DXBUFFER* ppAdjacency, LPD3DXBUFFER* ppMaterials, LPD3DXBUFFER* ppEffectInstances, DWORD* pNumMaterials,
00054       LPD3DXMESH* ppMesh) {
00055     if (this->pd3dDevice == NULL) {
00056       LOG(LOG_PRIORITY::ERR, "Cannot load mesh from file '" + file + "' because the DirectX device was not activated.");
00057       return -1;
00058     }
00059     
00060     HRESULT hr;
00061     
00062     // Load mesh from designated file string
00063     hr = D3DXLoadMeshFromX(file.c_str(), options, this->pd3dDevice, ppAdjacency, ppMaterials, ppEffectInstances, pNumMaterials, ppMesh);
00064     
00065     if (FAILED(hr)) {
00066       LOG(LOG_PRIORITY::MISSRESS, "Failed to load mesh from file: " + file);
00067     }
00068     
00069     return hr;
00070   }
00071 }