void DrawWidget::initializeGL() { renderer.initGL(width(), height(), false); resizeGL(width(), height()); initPipeline(); resetScene(); }
void Reloadable::reload() { initBuffers(); initPipeline(); initVBO(); initVAO(); initUniformsCache(); }
bool initialize() { if (false == checkRuntimeConfig()) return false; Timing::initialize(); return (OpenGL::initialize() && initScheduling() && initPipeline()); }
Mesh::Mesh( Engine* engine, const Material& material, core::Texture2D* diffuseMap, core::Texture2D* normalMap, core::Texture2D* specularMap, core::Program* program, core::Program* programShadow, core::Program* programShadowColor, core::Program* programOcclusion, core::Program* programAmbientOcclusionGeometry, core::Program* programAmbientOcclusionColor, LightSystem* lights, core::VertexBufferBasic* vbo, core::IndexBuffer* ibo, #ifdef FILLWAVE_MODEL_LOADER_ASSIMP Animator* animator, #endif /* FILLWAVE_MODEL_LOADER_ASSIMP */ GLenum renderMode, core::VertexArray* vao) : IReloadable(engine, vao), mMaterial(material), mDiffuseMap(diffuseMap), mNormalMap(normalMap), mSpecularMap(specularMap), mProgram(program), mProgramShadow(programShadow), mProgramShadowColor(programShadowColor), mProgramOQ(programOcclusion), mProgramAOGeometry(programAmbientOcclusionGeometry), mProgramAOColor(programAmbientOcclusionColor), mRenderMode(renderMode), mIBO(ibo), mVBO(vbo), mLights(lights) #ifdef FILLWAVE_MODEL_LOADER_ASSIMP , mAnimator(animator) #endif /* FILLWAVE_MODEL_LOADER_ASSIMP */ #ifdef FILLWAVE_GLES_3_0 #else , mConditionalRendering(GL_QUERY_WAIT) #endif { initPipeline(); initVBO(); initVAO(); initUniformsCache(); }
RenderInterfaceDx11::RenderInterfaceDx11(HWND p_hWnd, int _techNr, int _passNr, int p_width, int p_height) { m_hWnd = p_hWnd; m_width = p_width; m_height = p_height; techNr = _techNr; passNr = _passNr; initDevice(); initEffect(); D3D11_RASTERIZER_DESC rasterizerDesc; rasterizerDesc.FillMode = D3D11_FILL_SOLID; rasterizerDesc.CullMode = D3D11_CULL_BACK; rasterizerDesc.FrontCounterClockwise = TRUE; // Changed it from CounterClockwise false to true, since it otherwise will be culled rasterizerDesc.DepthClipEnable = TRUE; rasterizerDesc.AntialiasedLineEnable = FALSE; rasterizerDesc.MultisampleEnable = FALSE; rasterizerDesc.DepthBias = 0; rasterizerDesc.DepthBiasClamp = 0.0f; rasterizerDesc.SlopeScaledDepthBias = 0.0f; rasterizerDesc.ScissorEnable = false; HR(m_device->CreateRasterizerState(&rasterizerDesc, &rs_scissorsOff)); rasterizerDesc.ScissorEnable = true; HR(m_device->CreateRasterizerState(&rasterizerDesc, &rs_scissorsOn)); m_context->RSSetState(rs_scissorsOff); defineInputElementDesc(); defineBlendState(); initPipeline(); initFxVars(); initDefaultTex(); }
void DrawTestsBaseClass::initialize (void) { const vk::VkDevice device = m_context.getDevice(); const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex(); const PipelineLayoutCreateInfo pipelineLayoutCreateInfo; m_pipelineLayout = vk::createPipelineLayout(m_vk, device, &pipelineLayoutCreateInfo); const vk::VkExtent3D targetImageExtent = { WIDTH, HEIGHT, 1 }; const ImageCreateInfo targetImageCreateInfo(vk::VK_IMAGE_TYPE_2D, m_colorAttachmentFormat, targetImageExtent, 1, 1, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_IMAGE_TILING_OPTIMAL, vk::VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | vk::VK_IMAGE_USAGE_TRANSFER_SRC_BIT | vk::VK_IMAGE_USAGE_TRANSFER_DST_BIT); m_colorTargetImage = Image::createAndAlloc(m_vk, device, targetImageCreateInfo, m_context.getDefaultAllocator(), m_context.getUniversalQueueFamilyIndex()); const ImageViewCreateInfo colorTargetViewInfo(m_colorTargetImage->object(), vk::VK_IMAGE_VIEW_TYPE_2D, m_colorAttachmentFormat); m_colorTargetView = vk::createImageView(m_vk, device, &colorTargetViewInfo); RenderPassCreateInfo renderPassCreateInfo; renderPassCreateInfo.addAttachment(AttachmentDescription(m_colorAttachmentFormat, vk::VK_SAMPLE_COUNT_1_BIT, vk::VK_ATTACHMENT_LOAD_OP_LOAD, vk::VK_ATTACHMENT_STORE_OP_STORE, vk::VK_ATTACHMENT_LOAD_OP_DONT_CARE, vk::VK_ATTACHMENT_STORE_OP_STORE, vk::VK_IMAGE_LAYOUT_GENERAL, vk::VK_IMAGE_LAYOUT_GENERAL)); const vk::VkAttachmentReference colorAttachmentReference = { 0, vk::VK_IMAGE_LAYOUT_GENERAL }; renderPassCreateInfo.addSubpass(SubpassDescription(vk::VK_PIPELINE_BIND_POINT_GRAPHICS, 0, 0, DE_NULL, 1, &colorAttachmentReference, DE_NULL, AttachmentReference(), 0, DE_NULL)); m_renderPass = vk::createRenderPass(m_vk, device, &renderPassCreateInfo); std::vector<vk::VkImageView> colorAttachments(1); colorAttachments[0] = *m_colorTargetView; const FramebufferCreateInfo framebufferCreateInfo(*m_renderPass, colorAttachments, WIDTH, HEIGHT, 1); m_framebuffer = vk::createFramebuffer(m_vk, device, &framebufferCreateInfo); const vk::VkVertexInputBindingDescription vertexInputBindingDescription = { 0, sizeof(VertexElementData), vk::VK_VERTEX_INPUT_RATE_VERTEX, }; const vk::VkVertexInputAttributeDescription vertexInputAttributeDescriptions[] = { { 0u, 0u, vk::VK_FORMAT_R32G32B32A32_SFLOAT, 0u }, // VertexElementData::position { 1u, 0u, vk::VK_FORMAT_R32G32B32A32_SFLOAT, static_cast<deUint32>(sizeof(tcu::Vec4)) }, // VertexElementData::color { 2u, 0u, vk::VK_FORMAT_R32_SINT, static_cast<deUint32>(sizeof(tcu::Vec4)) * 2 } // VertexElementData::refVertexIndex }; m_vertexInputState = PipelineCreateInfo::VertexInputState(1, &vertexInputBindingDescription, DE_LENGTH_OF_ARRAY(vertexInputAttributeDescriptions), vertexInputAttributeDescriptions); const vk::VkDeviceSize dataSize = m_data.size() * sizeof(VertexElementData); m_vertexBuffer = Buffer::createAndAlloc(m_vk, device, BufferCreateInfo(dataSize, vk::VK_BUFFER_USAGE_VERTEX_BUFFER_BIT), m_context.getDefaultAllocator(), vk::MemoryRequirement::HostVisible); deUint8* ptr = reinterpret_cast<deUint8*>(m_vertexBuffer->getBoundMemory().getHostPtr()); deMemcpy(ptr, &m_data[0], static_cast<size_t>(dataSize)); vk::flushMappedMemoryRange(m_vk, device, m_vertexBuffer->getBoundMemory().getMemory(), m_vertexBuffer->getBoundMemory().getOffset(), dataSize); const CmdPoolCreateInfo cmdPoolCreateInfo(queueFamilyIndex); m_cmdPool = vk::createCommandPool(m_vk, device, &cmdPoolCreateInfo); m_cmdBuffer = vk::allocateCommandBuffer(m_vk, device, *m_cmdPool, vk::VK_COMMAND_BUFFER_LEVEL_PRIMARY); initPipeline(device); }
void MinimalImpactTEDWriter::write(std::string filename) { updateInputs(); initPipeline(); int limitToISI = -1; if (optionLimitToISI) limitToISI = optionLimitToISI.as<int>() - SliceHashConfiguration::sectionOffset; if (optionWriteTedConditions) filename = "minimalImpactTEDconditions.txt"; // append ISI number to output filename if (limitToISI >= 0) filename = filename + "_" + optionLimitToISI.as<std::string>(); if (optionWriteTedConditions) { LOG_USER(minimalImpactTEDlog) << "writing ted conditions to " << filename << std::endl; } else { LOG_USER(minimalImpactTEDlog) << "writing ted coefficients to " << filename << std::endl; } // Remove the old file if( remove( filename.c_str() ) != 0 ) { LOG_DEBUG(minimalImpactTEDlog) << "Old file to output minimal impact TED approximation sucessfully deleted." << std::endl; } else { LOG_DEBUG(minimalImpactTEDlog) << "Could not delete old file to output minimal impact TED approximation." << std::endl; } // Open file for writing std::ofstream outfile; outfile.open(filename.c_str()); // Get a vector with all gold standard segments. const std::vector<boost::shared_ptr<Segment> > goldStandard = _goldStandard->getSegments(); int constant = 0; // Loop through variables std::set<unsigned int> variables = _problemConfiguration->getVariables(); LOG_USER(minimalImpactTEDlog) << "computing ted coefficients for " << variables.size() << " variables" << std::endl; if (optionWriteTedConditions) { outfile << "# hash: [hashes of flipped segments]" << std::endl; } else { outfile << "numVar " << variables.size() << std::endl; outfile << "# var_num costs # hash value_in_gs fs fm fp fn ( <- when flipped )" << std::endl; } std::set<unsigned int> goldStandardIds; foreach (boost::shared_ptr<Segment> s, goldStandard) goldStandardIds.insert(s->getId()); // create a map from segment ids to segment pointers std::map<unsigned int, boost::shared_ptr<Segment> > idToSegment; foreach (boost::shared_ptr<Segment> segment, _segments->getSegments()) idToSegment[segment->getId()] = segment; for ( unsigned int varNum = 0 ; varNum < variables.size() ; varNum++ ) { unsigned int segmentId = _problemConfiguration->getSegmentId(varNum); int interSectionInterval = _problemConfiguration->getInterSectionInterval(varNum); if (limitToISI >= 0) if (interSectionInterval != limitToISI) continue; std::string timerMessage = "\n\nMinimalImpactTEDWriter: variable " + boost::lexical_cast<std::string>(varNum) + ", %ws\n\n"; boost::timer::auto_cpu_timer timer(timerMessage); // re-create the pipeline for the current segment and its inter-section // interval if (!optionWriteTedConditions) updatePipeline(interSectionInterval, optionNumAdjacentSections.as<int>()); // Is the segment that corresponds to the variable part of the gold standard? bool isContained = (goldStandardIds.count(segmentId) > 0); // get the hash value of this segment SegmentHash segmentHash = idToSegment[segmentId]->hashValue(); // pin the value of the current variable to its opposite _linearSolver->pinVariable(varNum, (isContained ? 0 : 1)); if (!optionWriteTedConditions) { pipeline::Value<TolerantEditDistanceErrors> errors = _teDistance->getOutput("errors"); int sumErrors = errors->getNumSplits() + errors->getNumMerges() + errors->getNumFalsePositives() + errors->getNumFalseNegatives(); outfile << "c" << varNum << " "; outfile << (isContained ? -sumErrors : sumErrors) << " "; outfile << "# "; outfile << segmentHash << " "; outfile << (isContained ? 1 : 0) << " "; outfile << errors->getNumSplits() << " "; outfile << errors->getNumMerges() << " "; outfile << errors->getNumFalsePositives() << " "; outfile << errors->getNumFalseNegatives() << std::endl; if (isContained) { // Forced segment to not be part of the reconstruction. // This resulted in a number of errors that are going to be stored in the constant. // To make net 0 errors when the variable is on, minus the number of errors will be written to the file. constant += sumErrors; } } else { pipeline::Value<Solution> solution = _linearSolver->getOutput("solution"); outfile << segmentHash << ":"; for (unsigned int i = 0; i < variables.size(); i++) { unsigned int id = _problemConfiguration->getSegmentId(i); // was flipped? if ((*solution)[i] != goldStandardIds.count(id)) outfile << " " << idToSegment[id]->hashValue(); } outfile << std::endl; } // Remove constraint _linearSolver->unpinVariable(varNum); } if (!optionWriteTedConditions) { // Write constant to file outfile << "constant " << constant << std::endl; } outfile.close(); }
void DXWindow::initD3D() { HRESULT hr; //Describe our SwapChain Buffer DXGI_MODE_DESC bufferDesc; ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC)); bufferDesc.Width = mWidth; bufferDesc.Height = mHeight; bufferDesc.RefreshRate.Numerator = 60; bufferDesc.RefreshRate.Denominator = 1; bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // create a struct to hold information about the swap chain DXGI_SWAP_CHAIN_DESC swapChainDesc; // clear out the struct for use ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); swapChainDesc.BufferDesc = bufferDesc; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = 1; swapChainDesc.OutputWindow = hWnd; swapChainDesc.Windowed = TRUE; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; // allow full-screen switching by Alt+Enter // create a device, device context and swap chain using the information in the scd struct hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &swapChainDesc, &mSwapchain, &mDevice, NULL, &mDeviceContext); if (SUCCEEDED(hr)) { std::cout << "Opened D3D HARDWARE Context!\n"; } else { std::cout << "Could not open D3D HARDWARE Context!\n"; exit(-1); } D3D_FEATURE_LEVEL featureLevel = mDevice->GetFeatureLevel(); std::unordered_map<D3D_FEATURE_LEVEL, std::string> featureLevelMapping; featureLevelMapping[D3D_FEATURE_LEVEL_9_1] = "D3D_FEATURE_LEVEL_9_1"; featureLevelMapping[D3D_FEATURE_LEVEL_9_2] = "D3D_FEATURE_LEVEL_9_2"; featureLevelMapping[D3D_FEATURE_LEVEL_9_3] = "D3D_FEATURE_LEVEL_9_3"; featureLevelMapping[D3D_FEATURE_LEVEL_10_0] = "D3D_FEATURE_LEVEL_10_0"; featureLevelMapping[D3D_FEATURE_LEVEL_10_1] = "D3D_FEATURE_LEVEL_10_1"; featureLevelMapping[D3D_FEATURE_LEVEL_11_0] = "D3D_FEATURE_LEVEL_11_0"; //featureLevelMapping[D3D_FEATURE_LEVEL_11_1] = "D3D_FEATURE_LEVEL_11_1"; std::cout << "Rendering with feature level " << featureLevelMapping[featureLevel] << "!\n"; // SET RENDER TARGET { // get the address of the back buffer ID3D11Texture2D *pBackBuffer; mSwapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); // use the back buffer address to create the render target hr = mDevice->CreateRenderTargetView(pBackBuffer, NULL, &mBackbuffer); if (SUCCEEDED(hr)) { std::cout << "Created back buffer!\n"; } else { std::cout << "Could not create back buffer!\n"; exit(-1); } pBackBuffer->Release(); //Describe our Depth/Stencil Buffer D3D11_TEXTURE2D_DESC depthStencilDesc; depthStencilDesc.Width = mWidth; depthStencilDesc.Height = mHeight; depthStencilDesc.MipLevels = 1; depthStencilDesc.ArraySize = 1; depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; depthStencilDesc.SampleDesc.Count = 1; depthStencilDesc.SampleDesc.Quality = 0; depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.MiscFlags = 0; //Create the Depth/Stencil View mDevice->CreateTexture2D(&depthStencilDesc, NULL, &mDepthStencilBuffer); mDevice->CreateDepthStencilView(mDepthStencilBuffer, NULL, &mDepthStencilView); D3D11_RASTERIZER_DESC gRasterizerStateDesc; // clear out the struct for use ZeroMemory(&gRasterizerStateDesc, sizeof(D3D11_RASTERIZER_DESC)); gRasterizerStateDesc.FillMode = D3D11_FILL_SOLID; gRasterizerStateDesc.CullMode = D3D11_CULL_NONE; gRasterizerStateDesc.FrontCounterClockwise = false; ID3D11RasterizerState* gRasterizerState; mDevice->CreateRasterizerState(&gRasterizerStateDesc, &gRasterizerState); mDeviceContext->RSSetState(gRasterizerState); //Set our Render Target mDeviceContext->OMSetRenderTargets(1, &mBackbuffer, mDepthStencilView); } // SET VIEWPORT { // Set the viewport D3D11_VIEWPORT viewport; ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT)); viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = mWidth; viewport.Height = mHeight; mDeviceContext->RSSetViewports(1, &viewport); } initPipeline(); initGraphics(); }