BaseCamera::BaseCamera(float nearZ, float farZ) : m_nearZ(nearZ) , m_farZ(farZ) { OC_ASSERT(m_nearZ >= 0.0f); OC_ASSERT(m_farZ >= 0.0f); OC_ASSERT(m_nearZ < m_farZ); }
FirstPersonCamera::FirstPersonCamera(float aspectRatio, float fieldOfView, float nearClip, float farClip) : BaseCamera(nearClip, farClip) , m_aspectRatio(aspectRatio) , m_fov(fieldOfView) { OC_ASSERT(m_aspectRatio > 0); OC_ASSERT(m_fov > 0 && m_fov < OC_PI); CreateProjection(); }
void LightDemo::InitFX() { std::ifstream fin("fx/Lighting.fxo", std::ios::binary); OC_ASSERT(fin.good()); fin.seekg(0, std::ios_base::end); int size = (int)fin.tellg(); fin.seekg(0, std::ios_base::beg); std::vector<char> compiledShader(size); fin.read(&compiledShader[0], size); fin.close(); HR(D3DX11CreateEffectFromMemory(&compiledShader[0], size, 0, m_dxDevice.Get(), m_fx.GetAddressOf())); m_tech = m_fx->GetTechniqueByName("LightTech"); m_fxWorldViewProj = m_fx->GetVariableByName("gWorldViewProj")->AsMatrix(); m_fxWorld = m_fx->GetVariableByName("gWorld")->AsMatrix(); m_fxWorldInvTranspose = m_fx->GetVariableByName("gWorldInvTranspose")->AsMatrix(); m_fxEyePosW = m_fx->GetVariableByName("gEyePosW")->AsVector(); m_fxDirLight = m_fx->GetVariableByName("gDirLight"); m_fxPointLight = m_fx->GetVariableByName("gPointLight"); m_fxSpotLight = m_fx->GetVariableByName("gSpotLight"); m_fxMaterial = m_fx->GetVariableByName("gMaterial"); }
void Graphic::Resize(uint32 width, uint32 heigth) { OC_ASSERT(m_dxImmediateContext.Get()); OC_ASSERT(m_dxDevice.Get()); OC_ASSERT(m_swapChain.Get()); m_backBufferWidth = width; m_backBufferHeigth = heigth; // Release the old views, as they hold references to the buffers we // will be destroying. Also release the old depth/stencil buffer. m_backBufferRTV.Reset(); m_depthStencilView.Reset(); m_depthStencilBuffer.Reset(); // Resize the swap chain and recreate the render target view. // NOTE: If we do not resize the buffers the display will be stretched to the window size DXCall(m_swapChain->ResizeBuffers(1, m_backBufferWidth, m_backBufferHeigth, DXGI_FORMAT_R8G8B8A8_UNORM, 0)); BindDefaultBuffers(); }
GfxSystem::GfxViewport::GfxViewport( ResourceSystem::ResourcePtr texture ): mPosition(Vector2_Zero), mSize(Vector2_Zero), mTexture(InvalidTextureHandle), mRelativeScale(false), mGridEnabled(true) { OC_ASSERT(texture->GetType() == ResourceSystem::RESTYPE_TEXTURE); TexturePtr textureResource = (TexturePtr)texture; mTexture = textureResource->GetTexture(); mSize.x = (float32)textureResource->GetWidth(); mSize.y = (float32)textureResource->GetHeight(); }
Effect::Effect(ID3D11Device* device, const std::string& filename) : m_fx(nullptr) { std::ifstream fin(filename, std::ios::binary); OC_ASSERT(fin.good()); fin.seekg(0, std::ios_base::end); int size = (int)fin.tellg(); fin.seekg(0, std::ios_base::beg); std::vector<char> compiledShader(size); fin.read(&compiledShader[0], size); fin.close(); HR(D3DX11CreateEffectFromMemory(&compiledShader[0], size, 0, device, m_fx.GetAddressOf())); }
bool Graphic::Initialize(HWND hwnd, const GraphicConfig& config) { OC_LOG_INFO("GraphicSystem initializing"); m_hwnd = hwnd; m_config = config; m_backBufferWidth = m_config.m_windowWitdh; m_backBufferHeigth = m_config.m_windowHeight; OC_ASSERT_MSG(m_config.m_MSAASample > 0, "Invalid MSAA samples!"); // Minimum is 1 // Create the device and device context. UINT createDeviceFlags = D3D11_CREATE_DEVICE_SINGLETHREADED; #if defined(OC_DEBUG) createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif D3D_FEATURE_LEVEL featureLevel; HRESULT hr = D3D11CreateDevice( 0, // default adapter D3D_DRIVER_TYPE_HARDWARE, 0, // no software device createDeviceFlags, 0, // default feature level array (select greatest supported -> DX11) 0, // number of feature level in the array above D3D11_SDK_VERSION, //SDK version m_dxDevice.GetAddressOf(), //Created device &featureLevel, //Selected feature level m_dxImmediateContext.GetAddressOf()); //Device context if (FAILED(hr)) { OC_LOG_ERROR("D3D11CreateDevice failed"); return false; } if (featureLevel != D3D_FEATURE_LEVEL_11_0) { OC_LOG_ERROR("Direct3D Feature Level 11 unsupported"); return false; } #if defined(OC_DEBUG) ComPtr<ID3D11InfoQueue> infoQueue; DXCall(m_dxDevice->QueryInterface(__uuidof(ID3D11InfoQueue), (void**)infoQueue.GetAddressOf())); infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, TRUE); infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, TRUE); #endif // Check 4X MSAA quality support for our back buffer format. // All Direct3D 11 capable devices support 4X MSAA for all render // target formats, so we only need to check quality support. UINT MSAAQuality; DXCall(m_dxDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, m_config.m_MSAASample, &MSAAQuality)); // Validate quality OC_ASSERT(MSAAQuality > 0); OC_ASSERT_MSG(m_config.m_selectBestMSAAQuality || m_config.m_MSAAQuality <= MSAAQuality -1, "Invalid MSAA quality"); if (m_config.m_selectBestMSAAQuality) { m_config.m_MSAAQuality = MSAAQuality - 1; } DXGI_SWAP_CHAIN_DESC sd; ZeroMemory(&sd, sizeof(DXGI_SWAP_CHAIN_DESC)); // Describe the back buffer sd.BufferDesc.Width = m_backBufferWidth; sd.BufferDesc.Height = m_backBufferHeigth; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; //Texture format of the back buffer ( 8 bits rgb + alpha) sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // Multisampling (anti-aliasing), all DX11 device support at least 4X multisampling for all render target format sd.SampleDesc.Count = m_config.m_MSAASample; sd.SampleDesc.Quality = m_config.m_MSAAQuality - 1; // Describes the surface usage and CPU access options for the back buffer. // The back buffer can be used for shader input or render-target output. sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = m_hwnd; sd.Windowed = !m_config.m_fullScreen; // Options for handling pixels in a display surface after calling IDXGISwapChain1::Present1. sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // Options for swap-chain behavior. sd.Flags = 0; // NOTE : This flag can change the resolution... //sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // To correctly create the swap chain, we must use the IDXGIFactory that was // used to create the device. If we tried to use a different IDXGIFactory instance // (by calling CreateDXGIFactory), we get an error: "IDXGIFactory::CreateSwapChain: // This function is being called with a device from a different IDXGIFactory." ComPtr<IDXGIDevice> dxgiDevice = nullptr; DXCall(m_dxDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)dxgiDevice.GetAddressOf())); ComPtr<IDXGIAdapter> dxgiAdapter = nullptr; DXCall(dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)dxgiAdapter.GetAddressOf())); ComPtr<IDXGIFactory> dxgiFactory = nullptr; DXCall(dxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)dxgiFactory.GetAddressOf())); DXCall(dxgiFactory->CreateSwapChain(m_dxDevice.Get(), &sd, m_swapChain.GetAddressOf())); // The remaining steps that need to be carried out for d3d creation // also need to be executed every time the window is resized. BindDefaultBuffers(); OC_LOG_INFO("GraphicSystem initialize completed"); return true; }
/** Output one property tag and value \param lpProp the property to print \param sep a separator / spacer to insert in front of the label */ _PUBLIC_ void mapidump_SPropValue(struct SPropValue lpProp, const char *sep) { const char *proptag; const void *data; TALLOC_CTX *mem_ctx = NULL; const struct StringArray_r *StringArray_r = NULL; const struct StringArrayW_r *StringArrayW_r = NULL; const struct BinaryArray_r *BinaryArray_r = NULL; const struct LongArray_r *LongArray_r = NULL; uint32_t i; proptag = get_proptag_name(lpProp.ulPropTag); if (!proptag) { mem_ctx = talloc_named(NULL, 0, "mapidump_SPropValue"); proptag = talloc_asprintf(mem_ctx, "0x%.8x", lpProp.ulPropTag); } switch(lpProp.ulPropTag & 0xFFFF) { case PT_SHORT: data = get_SPropValue_data(&lpProp); printf("%s%s: 0x%x\n", sep?sep:"", proptag, (*(const uint16_t *)data)); break; case PT_LONG: case PT_OBJECT: data = get_SPropValue_data(&lpProp); printf("%s%s: %u\n", sep?sep:"", proptag, (*(const uint32_t *)data)); break; case PT_DOUBLE: data = get_SPropValue_data(&lpProp); printf("%s%s: %f\n", sep?sep:"", proptag, (*(const double *)data)); break; case PT_BOOLEAN: data = get_SPropValue_data(&lpProp); printf("%s%s: 0x%x\n", sep?sep:"", proptag, (*(const uint8_t *)data)); break; case PT_I8: data = get_SPropValue_data(&lpProp); printf("%s%s: %.16"PRIx64"\n", sep?sep:"", proptag, (*(const uint64_t *)data)); break; case PT_STRING8: case PT_UNICODE: data = get_SPropValue_data(&lpProp); printf("%s%s:", sep?sep:"", proptag); if (data && ((*(const uint16_t *)data) == 0x0000)) { /* its an empty string */ printf("\n"); } else if (data && ((*(enum MAPISTATUS *)data) != MAPI_E_NOT_FOUND)) { /* its a valid string */ printf(" %s\n", (const char *)data); } else { /* its a null or otherwise problematic string */ printf(" (NULL)\n"); } break; case PT_SYSTIME: mapidump_date_SPropValue(lpProp, proptag, sep); break; case PT_ERROR: data = get_SPropValue_data(&lpProp); printf("%s%s_ERROR: 0x%.8x\n", sep?sep:"", proptag, (*(const uint32_t *)data)); break; case PT_CLSID: { const uint8_t *ab = (const uint8_t *) get_SPropValue_data(&lpProp); printf("%s%s: ", sep?sep:"", proptag); for (i = 0; i < 15; ++i) { printf("%02x ", ab[i]); } printf("%x\n", ab[15]); break; } case PT_SVREID: case PT_BINARY: data = get_SPropValue_data(&lpProp); if (data) { printf("%s%s:\n", sep?sep:"", proptag); dump_data(0, ((const struct Binary_r *)data)->lpb, ((const struct Binary_r *)data)->cb); } else { printf("%s%s: (NULL)\n", sep?sep:"", proptag); } break; case PT_MV_LONG: LongArray_r = (const struct LongArray_r *) get_SPropValue_data(&lpProp); printf("%s%s ", sep?sep:"", proptag); for (i = 0; i < LongArray_r->cValues - 1; i++) { printf("0x%.8x, ", LongArray_r->lpl[i]); } printf("0x%.8x\n", LongArray_r->lpl[i]); break; case PT_MV_STRING8: StringArray_r = (const struct StringArray_r *) get_SPropValue_data(&lpProp); printf("%s%s: ", sep?sep:"", proptag); for (i = 0; i < StringArray_r->cValues - 1; i++) { printf("%s, ", StringArray_r->lppszA[i]); } printf("%s\n", StringArray_r->lppszA[i]); break; case PT_MV_UNICODE: StringArrayW_r = (const struct StringArrayW_r *) get_SPropValue_data(&lpProp); printf("%s%s: ", sep?sep:"", proptag); for (i = 0; i < StringArrayW_r->cValues - 1; i++) { printf("%s, ", StringArrayW_r->lppszW[i]); } printf("%s\n", StringArrayW_r->lppszW[i]); break; case PT_MV_BINARY: BinaryArray_r = (const struct BinaryArray_r *) get_SPropValue_data(&lpProp); printf("%s%s: ARRAY(%d)\n", sep?sep:"", proptag, BinaryArray_r->cValues); for (i = 0; i < BinaryArray_r->cValues; i++) { printf("\tPT_MV_BINARY [%d]:\n", i); dump_data(0, BinaryArray_r->lpbin[i].lpb, BinaryArray_r->lpbin[i].cb); } break; default: /* If you hit this assert, you'll need to implement whatever type is missing */ OC_ASSERT(0); break; } if (mem_ctx) { talloc_free(mem_ctx); } }