MCPcopy Create free account
hub / github.com/KhronosGroup/Vulkan-Samples / prepare

Method prepare

samples/extensions/open_gl_interop/open_gl_interop.cpp:544–614  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

542}
543
544bool OpenGLInterop::prepare(const vkb::ApplicationOptions &options)
545{
546 if (!ApiVulkanSample::prepare(options))
547 {
548 return false;
549 }
550
551 // Create off screen context
552 gl_context = new OffscreenContext{};
553 gl_data = new GLData{};
554
555 prepare_shared_resources();
556
557 gl_data->program = gl_context->build_program(OPENGL_VERTEX_SHADER, OPENGL_FRAGMENT_SHADER);
558
559 timer.start();
560
561 glDisable(GL_DEPTH_TEST);
562
563 // Create the texture for the FBO color attachment.
564 // This only reserves the ID, it doesn't allocate memory
565 glGenTextures(1, &gl_data->color);
566 glBindTexture(GL_TEXTURE_2D, gl_data->color);
567
568 // Create the GL identifiers
569
570 // semaphores
571 glGenSemaphoresEXT(1, &gl_data->gl_ready);
572 glGenSemaphoresEXT(1, &gl_data->gl_complete);
573 // memory
574 glCreateMemoryObjectsEXT(1, &gl_data->mem);
575
576 GLint dedicated = GL_TRUE;
577 glMemoryObjectParameterivEXT(gl_data->mem, GL_DEDICATED_MEMORY_OBJECT_EXT, &dedicated);
578
579 // Platform specific import.
580 glImportSemaphore(gl_data->gl_ready, GL_HANDLE_TYPE, shareHandles.gl_ready);
581 glImportSemaphore(gl_data->gl_complete, GL_HANDLE_TYPE, shareHandles.gl_complete);
582 glImportMemory(gl_data->mem, sharedTexture.allocationSize, GL_HANDLE_TYPE, shareHandles.memory);
583
584 // Use the imported memory as backing for the OpenGL texture. The internalFormat, dimensions
585 // and mip count should match the ones used by Vulkan to create the image and determine it's memory
586 // allocation.
587 glTextureStorageMem2DEXT(gl_data->color, 1, GL_RGBA8, SHARED_TEXTURE_DIMENSION,
588 SHARED_TEXTURE_DIMENSION, gl_data->mem, 0);
589 glBindTexture(GL_TEXTURE_2D, 0);
590
591 // The remaining initialization code is all standard OpenGL
592 glGenVertexArrays(1, &gl_data->vao);
593 glBindVertexArray(gl_data->vao);
594
595 glGenFramebuffers(1, &gl_data->fbo);
596 glBindFramebuffer(GL_FRAMEBUFFER, gl_data->fbo);
597 glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, gl_data->color, 0);
598
599 glUseProgram(gl_data->program);
600 glProgramUniform3f(gl_data->program, 0, static_cast<float>(SHARED_TEXTURE_DIMENSION),
601 static_cast<float>(SHARED_TEXTURE_DIMENSION), 0.0f);

Callers

nothing calls this directly

Calls 2

build_programMethod · 0.80
startMethod · 0.80

Tested by

no test coverage detected