Пример #1
0
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKHR(
    VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
    VkSurfaceKHR surface, VkBool32 *pSupported) {
  const auto instance_dat = *GetGlobalContext().GetInstanceData(
      GetGlobalContext().GetPhysicalDeviceData(physicalDevice)->instance_);

  for (uint32_t i = 0; i <= queueFamilyIndex; ++i) {
    uint32_t property_count = 0;
    instance_dat.vkGetPhysicalDeviceQueueFamilyProperties(
        physicalDevice, &property_count, nullptr);
    assert(property_count > queueFamilyIndex);

    std::vector<VkQueueFamilyProperties> properties(property_count);
    instance_dat.vkGetPhysicalDeviceQueueFamilyProperties(
        physicalDevice, &property_count, properties.data());

    if (properties[queueFamilyIndex].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
      *pSupported = (i == queueFamilyIndex);
      return VK_SUCCESS;
    }
  }

  // For now only support the FIRST graphics queue. It looks like all of
  // the commands we will have to run are transfer commands, so
  // we can probably get away with ANY queue (other than
  // SPARSE_BINDING).
  *pSupported = false;
  return VK_SUCCESS;
}
Пример #2
0
VKAPI_ATTR VkResult VKAPI_CALL vkCreateSwapchainKHR(
    VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo,
    const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) {

  DeviceData &dev_dat = *GetGlobalContext().GetDeviceData(device);
  PhysicalDeviceData &pdd =
      *GetGlobalContext().GetPhysicalDeviceData(dev_dat.physicalDevice);
  InstanceData &inst_dat = *GetGlobalContext().GetInstanceData(pdd.instance_);

  uint32_t property_count = 0;
  inst_dat.vkGetPhysicalDeviceQueueFamilyProperties(dev_dat.physicalDevice,
                                                    &property_count, nullptr);

  std::vector<VkQueueFamilyProperties> queue_properties(property_count);
  inst_dat.vkGetPhysicalDeviceQueueFamilyProperties(
      dev_dat.physicalDevice, &property_count, queue_properties.data());

  size_t queue = 0;
  for (; queue < queue_properties.size(); ++queue) {
    if (queue_properties[queue].queueFlags & VK_QUEUE_GRAPHICS_BIT)
      break;
  }

  assert(queue < queue_properties.size());

  *pSwapchain = reinterpret_cast<VkSwapchainKHR>(new VirtualSwapchain(
      device, queue, &pdd.physical_device_properties_, &pdd.memory_properties_,
      &dev_dat, pCreateInfo, pAllocator));
  return VK_SUCCESS;
}
Пример #3
0
void CreditsState::Update(){
	mUpdateTime += mFrameRateDeltaTime;
	if(!mStartedFinalStage){
		if(mUpdateTime >= UPDATE_TIME){
			if(mShowFull){
				mWaitTime += mFrameRateDeltaTime;
				if(mWaitTime >= WAIT_TIME){
					mWaitTime = 0.f;
					mUpdateTime = 0.f;
					mShowFull = false;
				}
			}else{
				mShowFull = true;
				mCurrentText ++;
				if(mCurrentText >= TEXT_MAX){ mStartedFinalStage = true; }
				mUpdateTime = 0.f;
			}
		}
	}else{
		if(mDoneFinalStage){
			GetGlobalContext().gameStateManager->Pop();
		}else{
			if(mTankSmasher.GetPosition().y <= ((Game::WINDOW_HEIGHT / 2) - 50)){
				if(mUpdateTime >= (WAIT_TIME + UPDATE_TIME)) mDoneFinalStage = true;
			}else{
				mTankSmasher.Move(0, -50 * mFrameRateDeltaTime);
				mUpdateTime = 0.f;
			}
		}
	}
}
Пример #4
0
VKAPI_ATTR VkResult VKAPI_CALL
vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
  // We submit to the queue the commands set up by the virtual swapchain.
  // This will start a copy operation from the image to the swapchain
  // buffers.
  uint32_t res = VK_SUCCESS;
  std::vector<VkPipelineStageFlags> pipeline_stages(
      pPresentInfo->waitSemaphoreCount, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
  for (size_t i = 0; i < pPresentInfo->swapchainCount; ++i) {
    uint32_t image_index = pPresentInfo->pImageIndices[i];
    VirtualSwapchain *swp =
        reinterpret_cast<VirtualSwapchain *>(pPresentInfo->pSwapchains[i]);

    VkSubmitInfo submitInfo{
        VK_STRUCTURE_TYPE_SUBMIT_INFO,                    // sType
        nullptr,                                          // nullptr
        i == 0 ? pPresentInfo->waitSemaphoreCount : 0,    // waitSemaphoreCount
        i == 0 ? pPresentInfo->pWaitSemaphores : nullptr, // pWaitSemaphores
        i == 0 ? pipeline_stages.data() : nullptr,        // pWaitDstStageMask
        1,                                                // commandBufferCount
        &swp->GetCommandBuffer(image_index),              // pCommandBuffers
        0,                                                // semaphoreCount
        nullptr                                           // pSemaphores
    };

    res |= GetGlobalContext().GetQueueData(queue)->vkQueueSubmit(
        queue, 1, &submitInfo, swp->GetFence(image_index));
    swp->NotifySubmitted(image_index);
  }

  return VkResult(res);
}
Пример #5
0
   void ScriptSystem::Tick(const dtEntity::Message& m)
   {
      if(mGlobalTickFunction.IsEmpty())
      {
         return;
      }

      HandleScope scope;  
      Context::Scope context_scope(GetGlobalContext());

      const dtEntity::TickMessage& msg = static_cast<const dtEntity::TickMessage&>(m);

      TryCatch try_catch;
      Handle<Value> argv[3] = {
         Number::New(msg.GetDeltaSimTime()),
         Number::New(msg.GetSimulationTime()),
         Uint32::New(osg::Timer::instance()->time_m())
      };

      Handle<Value> ret = mGlobalTickFunction->Call(mGlobalTickFunction, 3, argv);

      if(ret.IsEmpty())
      {
         ReportException(&try_catch);
      }

   }
Пример #6
0
VKAPI_ATTR void VKAPI_CALL vkCmdWaitEvents(
    VkCommandBuffer commandBuffer, uint32_t eventCount, const VkEvent *pEvents,
    VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask,
    uint32_t memoryBarrierCount, const VkMemoryBarrier *pMemoryBarriers,
    uint32_t bufferMemoryBarrierCount,
    const VkBufferMemoryBarrier *pBufferMemoryBarriers,
    uint32_t imageMemoryBarrierCount,
    const VkImageMemoryBarrier *pImageMemoryBarriers) {

  std::vector<VkImageMemoryBarrier> imageBarriers(imageMemoryBarrierCount);
  for (size_t i = 0; i < imageMemoryBarrierCount; ++i) {
    imageBarriers[i] = pImageMemoryBarriers[i];
    if (imageBarriers[i].oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
      imageBarriers[i].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
      imageBarriers[i].srcAccessMask |= VK_ACCESS_TRANSFER_READ_BIT;
    }
    if (imageBarriers[i].newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
      imageBarriers[i].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
      imageBarriers[i].dstAccessMask |= VK_ACCESS_TRANSFER_READ_BIT;
    }
  }
  PFN_vkCmdWaitEvents func =
      GetGlobalContext().GetCommandBufferData(commandBuffer)->vkCmdWaitEvents;

  func(commandBuffer, eventCount, pEvents, srcStageMask, dstStageMask,
       memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount,
       pBufferMemoryBarriers, imageMemoryBarrierCount, imageBarriers.data());
}
Пример #7
0
// We actually have to be able to submit data to the Queue right now.
// The user can supply either a semaphore, or a fence or both to this function.
// Because of this, once the image is available we have to submit
// a command to the queue to signal these.
VKAPI_ATTR VkResult VKAPI_CALL vkAcquireNextImageKHR(
    VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
    VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex) {
  VirtualSwapchain *swp = reinterpret_cast<VirtualSwapchain *>(swapchain);
  if (!swp->GetImage(timeout, pImageIndex)) {
    return timeout == 0 ? VK_NOT_READY : VK_TIMEOUT;
  }

  // It is important that we do not keep the lock here.
  // *GetGlobalContext().GetDeviceData() only holds the lock
  // for the duration of the call, if we instead do something like
  // auto dat = GetGlobalContext().GetDeviceData(device),
  // then the lock will be let go when dat is destroyed, which is
  // AFTER swapchain::vkQueueSubmit, this would be a priority
  // inversion on the locks.
  DeviceData &dat = *GetGlobalContext().GetDeviceData(device);
  VkQueue q;

  dat.vkGetDeviceQueue(device, swp->DeviceQueue(), 0, &q);

  bool has_semaphore = semaphore != VK_NULL_HANDLE;

  VkSubmitInfo info{VK_STRUCTURE_TYPE_SUBMIT_INFO, // sType
                    nullptr,                       // pNext
                    0,                             // waitSemaphoreCount
                    nullptr,                       // waitSemaphores
                    nullptr,                       // waitDstStageMask
                    0,                             // commandBufferCount
                    nullptr,                       // pCommandBuffers
                    (has_semaphore ? 1u : 0u),     // waitSemaphoreCount
                    (has_semaphore ? &semaphore : nullptr)};
  return swapchain::vkQueueSubmit(q, 1, &info, fence);

}
Пример #8
0
   Handle<Value> ScriptSystem::ExecuteJS(const std::string& code, const std::string& path)
   {
       // Init JavaScript context
      HandleScope handle_scope;
      Context::Scope context_scope(GetGlobalContext());

      // We're just about to compile the script; set up an error handler to
      // catch any exceptions the script might throw.
      TryCatch try_catch;

      // Compile the source code.
      Local<Script> compiled_script = Script::Compile(ToJSString(code), ToJSString(path));

      // if an exception occured
      if(try_catch.HasCaught())
      {
         ReportException(&try_catch);
   //      return try_catch;
      }

      // Run the script!
      Local<Value> ret = compiled_script->Run();
      if(try_catch.HasCaught())
      {
         ReportException(&try_catch);
   //      return try_catch;
      }

      FetchGlobalTickFunction();

      return handle_scope.Close(ret);
   }
EGLBoolean EGLAPIENTRY DestroyContext(EGLDisplay dpy, EGLContext ctx)
{
    EVENT("(EGLDisplay dpy = 0x%0.8p, EGLContext ctx = 0x%0.8p)", dpy, ctx);

    Display *display = static_cast<Display*>(dpy);
    gl::Context *context = static_cast<gl::Context*>(ctx);

    Error error = ValidateContext(display, context);
    if (error.isError())
    {
        SetGlobalError(error);
        return EGL_FALSE;
    }

    if (ctx == EGL_NO_CONTEXT)
    {
        SetGlobalError(Error(EGL_BAD_CONTEXT));
        return EGL_FALSE;
    }

    if (context == GetGlobalContext())
    {
        SetGlobalDisplay(NULL);
        SetGlobalContext(NULL);
    }

    display->destroyContext(context);

    SetGlobalError(Error(EGL_SUCCESS));
    return EGL_TRUE;
}
// EGL 1.4
EGLContext EGLAPIENTRY GetCurrentContext(void)
{
    EVENT("()");

    gl::Context *context = GetGlobalContext();

    SetGlobalError(Error(EGL_SUCCESS));
    return static_cast<EGLContext>(context);
}
Пример #11
0
VKAPI_ATTR VkResult VKAPI_CALL vkQueueSubmit(VkQueue queue,
                                             uint32_t submitCount,
                                             const VkSubmitInfo *pSubmits,
                                             VkFence fence) {
  // We actually DO have to lock here, we may share this queue with
  // vkAcquireNextImageKHR, which is not externally synchronized on Queue.
  return GetGlobalContext().GetQueueData(queue)->vkQueueSubmit(queue, submitCount,
                                                        pSubmits, fence);
}
Пример #12
0
   void ScriptSystem::SetupContext()
   {
      HandleScope handle_scope;
      if(!mGlobalContext.IsEmpty())
      {
         mGlobalContext.Dispose();
      }

      // create a template for the global object
      Handle<ObjectTemplate> global = ObjectTemplate::New();

      // create persistent global context
      mGlobalContext = Persistent<Context>::New(Context::New(NULL, global));

      // store pointer to script system into isolate data to have it globally available in javascript
      Isolate::GetCurrent()->SetData(this);

      RegisterGlobalFunctions(this, mGlobalContext);
      RegisterPropertyFunctions(this, mGlobalContext);

      InitializeAllWrappers(GetEntityManager());

      Handle<Context> context = GetGlobalContext();
      Context::Scope context_scope(context);
      Handle<FunctionTemplate> tmplt = FunctionTemplate::New();
      tmplt->InstanceTemplate()->SetInternalFieldCount(2);

      tmplt->SetClassName(String::New("ScriptSystem"));

      context->Global()->Set(String::New("Screen"), WrapScreen(this));

      dtEntity::InputInterface* ipiface = dtEntity::GetInputInterface();
      if(ipiface)
      {
         context->Global()->Set(String::New("Input"), WrapInputInterface(GetGlobalContext(), ipiface));
         context->Global()->Set(String::New("Axis"), WrapAxes(ipiface));
         context->Global()->Set(String::New("Key"), WrapKeys(ipiface));
      }

      context->Global()->Set(String::New("TouchPhase"), WrapTouchPhases());
      context->Global()->Set(String::New("Priority"), WrapPriorities());
      context->Global()->Set(String::New("Order"), WrapPriorities());

   }
Пример #13
0
// EGL 1.1
EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
{
    EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface surface = 0x%0.8p, EGLint buffer = %d)", dpy, surface, buffer);

    Display *display = static_cast<Display*>(dpy);
    Surface *eglSurface = static_cast<Surface*>(surface);

    Error error = ValidateSurface(display, eglSurface);
    if (error.isError())
    {
        SetGlobalError(error);
        return EGL_FALSE;
    }

    if (buffer != EGL_BACK_BUFFER)
    {
        SetGlobalError(Error(EGL_BAD_PARAMETER));
        return EGL_FALSE;
    }

    if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle())
    {
        SetGlobalError(Error(EGL_BAD_SURFACE));
        return EGL_FALSE;
    }

    if (eglSurface->getBoundTexture())
    {
        SetGlobalError(Error(EGL_BAD_ACCESS));
        return EGL_FALSE;
    }

    if (eglSurface->getTextureFormat() == EGL_NO_TEXTURE)
    {
        SetGlobalError(Error(EGL_BAD_MATCH));
        return EGL_FALSE;
    }

    gl::Context *context = GetGlobalContext();
    if (context)
    {
        gl::Texture *textureObject = context->getTargetTexture(GL_TEXTURE_2D);
        ASSERT(textureObject != NULL);

        if (textureObject->isImmutable())
        {
            SetGlobalError(Error(EGL_BAD_MATCH));
            return EGL_FALSE;
        }

        eglSurface->bindTexImage(textureObject, buffer);
    }

    SetGlobalError(Error(EGL_SUCCESS));
    return EGL_TRUE;
}
GLenum GL_APIENTRY GetGraphicsResetStatusEXT(void)
{
    EVENT("()");

    Context *context = GetGlobalContext();

    if (context)
    {
        return context->getResetStatus();
    }

    return GL_NO_ERROR;
}
Пример #15
0
CreditsState::CreditsState(){
	FontManager::FontPtr font = GetGlobalContext().fontManager->Get("Vera.ttf;40");

	mText[TEXT_PROGRAMMING].SetText("          Programming\n\nDmitry skwee Kudryavtsev");
	mText[TEXT_PROGRAMMING].SetFont(*font);
	mText[TEXT_PROGRAMMING].SetSize(20);
	mText[TEXT_PROGRAMMING].SetPosition((Game::WINDOW_WIDTH / 2) - 140, (Game::WINDOW_HEIGHT / 2) - 80);
	mText[TEXT_PROGRAMMING].SetBlendMode(sf::Blend::Alpha);

	mText[TEXT_MUSIC].SetText("  Background Music\n\n      Megaminute\n\nComposed By Akcija");
	mText[TEXT_MUSIC].SetFont(*font);
	mText[TEXT_MUSIC].SetSize(20);
	mText[TEXT_MUSIC].SetPosition((Game::WINDOW_WIDTH / 2) - 120, (Game::WINDOW_HEIGHT / 2) - 80);
	mText[TEXT_MUSIC].SetBlendMode(sf::Blend::Alpha);

	mText[TEXT_SOUND].SetText("  Sound Effects\n\nSoundBible.com");
	mText[TEXT_SOUND].SetFont(*font);
	mText[TEXT_SOUND].SetSize(20);
	mText[TEXT_SOUND].SetPosition((Game::WINDOW_WIDTH / 2) - 100, (Game::WINDOW_HEIGHT / 2) - 80);
	mText[TEXT_SOUND].SetBlendMode(sf::Blend::Alpha);

	mText[TEXT_MISC].SetText("        Special Thanks\n\n Unknown Sprite Authors\n\nGameDev.ru Beta Testers");
	mText[TEXT_MISC].SetFont(*font);
	mText[TEXT_MISC].SetSize(20);
	mText[TEXT_MISC].SetPosition((Game::WINDOW_WIDTH / 2) - 140, (Game::WINDOW_HEIGHT / 2) - 80);
	mText[TEXT_MISC].SetBlendMode(sf::Blend::Alpha);

	mTankSmasher.SetText("Tank Smasher");
	mTankSmasher.SetFont(*GetGlobalContext().fontManager->Get("BattleCity.ttf;52"));
	mTankSmasher.SetSize(42);
	mTankSmasher.SetPosition(40, Game::WINDOW_HEIGHT);
	mTankSmasher.SetColor(sf::Color(25, 71, 131));

	mUpdateTime = mWaitTime = mFinalStageTime = 0.f;
	mCurrentText = 0;
	mShowFull = true;
	mStartedFinalStage = mDoneFinalStage = false;
}
Пример #16
0
void CreditsState::HandleInput(const sf::Event& evt){
	if(evt.Type == sf::Event::KeyReleased){
		if(evt.Key.Code == sf::Key::Escape) GetGlobalContext().gameStateManager->Pop();
		else if(evt.Key.Code == sf::Key::Space){
			if(mStartedFinalStage) return;
			mCurrentText ++;
			mUpdateTime = mWaitTime = 0.f;
			mShowFull = true;
			if(mCurrentText >= TEXT_MAX){
				mStartedFinalStage = true;
			}
		}
	}
}
Пример #17
0
   void ScriptSystem::OnLoadScript(const dtEntity::Message& m)
   {
      const ExecuteScriptMessage& msg = static_cast<const ExecuteScriptMessage&>(m);

      HandleScope scope;
      Handle<Context> context = GetGlobalContext();      
      Context::Scope context_scope(context);
      
      if(msg.GetIncludeOnce())
      {
         ExecuteFileOnce(msg.GetPath());
      }
      else
      {
         ExecuteFile(msg.GetPath());
      }
   }
Пример #18
0
Context *GetValidGlobalContext()
{
    gl::Context *context = GetGlobalContext();
    if (context)
    {
        if (context->isContextLost())
        {
            context->recordError(gl::Error(GL_OUT_OF_MEMORY, "Context has been lost."));
            return nullptr;
        }
        else
        {
            return context;
        }
    }
    return nullptr;
}
Пример #19
0
void RegisterInstance(VkInstance instance, const InstanceData &data) {
  uint32_t num_devices = 0;
  data.vkEnumeratePhysicalDevices(instance, &num_devices, nullptr);

  std::vector<VkPhysicalDevice> physical_devices(num_devices);
  data.vkEnumeratePhysicalDevices(instance, &num_devices,
                                  physical_devices.data());

  auto physical_device_map = GetGlobalContext().GetPhysicalDeviceMap();

  for (VkPhysicalDevice physical_device : physical_devices) {
    PhysicalDeviceData dat{instance};
    data.vkGetPhysicalDeviceMemoryProperties(physical_device,
                                             &dat.memory_properties_);
    data.vkGetPhysicalDeviceProperties(physical_device,
                                       &dat.physical_device_properties_);
    (*physical_device_map)[physical_device] = dat;
  }
}
Пример #20
0
void OptionsState::HandleInput(const sf::Event& evt){
	if(evt.Type == sf::Event::KeyReleased){
		if(evt.Key.Code == sf::Key::Escape)
			GetGlobalContext().gameStateManager->Pop();
	}else if(evt.Type == sf::Event::KeyPressed){
		if(evt.Key.Code == sf::Key::Down) mSelectedOption ++;
		else if(evt.Key.Code == sf::Key::Up) mSelectedOption --;
		else if(evt.Key.Code == sf::Key::Return){
			switch(mSelectedOption){
			case OPTION_MUSIC:
				Game::gGameSettings.MusicOn = !Game::gGameSettings.MusicOn;
				break;
			case OPTION_SOUND:
				Game::gGameSettings.SoundOn = !Game::gGameSettings.SoundOn;
			default:
				break;
			}
		}
	}
}
Пример #21
0
   void ScriptSystem::FetchGlobalTickFunction()
   {
      HandleScope scope;
      Handle<Context> context = GetGlobalContext();

      mGlobalTickFunction.Clear();

      Handle<String> funcname = String::New("__executeTimeOuts");
      if(context->Global()->Has(funcname))
      {
         Handle<Value> func = context->Global()->Get(funcname);
         if(!func.IsEmpty())
         {
            Handle<Function> f = Handle<Function>::Cast(func);
            if(!f.IsEmpty())
            {
               mGlobalTickFunction = Persistent<Function>::New(f);
            }
         }
      }
   }
Пример #22
0
VKAPI_ATTR VkResult VKAPI_CALL vkCreateRenderPass(
    VkDevice device, const VkRenderPassCreateInfo *pCreateInfo,
    const VkAllocationCallbacks *pAllocator, VkRenderPass *pRenderPass) {
  VkRenderPassCreateInfo intercepted = *pCreateInfo;
  std::vector<VkAttachmentDescription> attachments(
      pCreateInfo->attachmentCount);

  for (size_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
    attachments[i] = pCreateInfo->pAttachments[i];
    if (attachments[i].initialLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
      attachments[i].initialLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
    }
    if (attachments[i].finalLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR) {
      attachments[i].finalLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
    }
  }
  PFN_vkCreateRenderPass func =
      GetGlobalContext().GetDeviceData(device)->vkCreateRenderPass;

  return func(device, &intercepted, pAllocator, pRenderPass);
}
Пример #23
0
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilitiesKHR(
    VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
    VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) {

  // It would be illegal for the program to call VkDestroyInstance here.
  // We do not need to lock the map for the whole time, just
  // long enough to get the data out. unordered_map guarantees that
  // even if re-hashing occurs, references remain valid.
  VkPhysicalDeviceProperties &properties =
      GetGlobalContext()
          .GetPhysicalDeviceData(physicalDevice)
          ->physical_device_properties_;

  pSurfaceCapabilities->minImageCount = 1;
  pSurfaceCapabilities->maxImageCount = 0;
  pSurfaceCapabilities->currentExtent = {0xFFFFFFFF, 0xFFFFFFFF};
  pSurfaceCapabilities->minImageExtent = {1, 1};
  pSurfaceCapabilities->maxImageExtent = {
      properties.limits.maxImageDimension2D,
      properties.limits.maxImageDimension2D};
  pSurfaceCapabilities->maxImageArrayLayers =
      properties.limits.maxImageArrayLayers;
  pSurfaceCapabilities->supportedTransforms =
      VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
  // TODO(awoloszyn): Handle all of the transforms eventually
  pSurfaceCapabilities->currentTransform =
      VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
  pSurfaceCapabilities->supportedCompositeAlpha =
      VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
  // TODO(awoloszyn): Handle all of the composite types.

  pSurfaceCapabilities->supportedUsageFlags =
      VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
  // TODO(awoloszyn): Find a good set of formats that we can use
  // for rendering.

  return VK_SUCCESS;
}
Пример #24
0
   void ScriptSystem::LoadAutoStartScripts(const std::string& path)
   {
      HandleScope handle_scope;
      Handle<Context> global = GetGlobalContext();
      Context::Scope context_scope(global);

      std::set<std::string> executed;

      osgDB::FilePathList paths = osgDB::getDataFilePathList();
      for(osgDB::FilePathList::iterator i = paths.begin(); i != paths.end(); ++i)
      {
         std::ostringstream autostartpath;
         autostartpath << *i << "/" << path;
         
         osgDB::FilePathList currentPathList;
         currentPathList.push_back(autostartpath.str());
         const std::string absPath = dtEntity::GetSystemInterface()->FindDataFile(autostartpath.str());

         if(!dtEntity::GetSystemInterface()->FileExists(absPath))
         {
            continue;
         }         
         
         osgDB::DirectoryContents contents = osgDB::getDirectoryContents(absPath);

         osgDB::DirectoryContents::const_iterator j;
         for(j = contents.begin(); j != contents.end(); ++j)
         {
            std::string filepath = *j;
            if(osgDB::getFileExtension(filepath).compare("js") != 0) continue;
            if(executed.find(filepath) == executed.end())
            {
               ExecuteFile(path + "/" + filepath);
               executed.insert(filepath);
            }
         }
      }      
   }
Пример #25
0
   Local<Value> ScriptSystem::ExecuteFile(const std::string& path)
   {
      HandleScope handle_scope;

      Handle<Script> script = GetScriptFromFile(path);

      if(!script.IsEmpty())
      {
         v8::Context::Scope context_scope(GetGlobalContext());
         TryCatch try_catch;
         Local<Value> ret = script->Run();

         FetchGlobalTickFunction();

         if(try_catch.HasCaught())
         {
            ReportException(&try_catch);
            return Local<Value>();
         }
         return handle_scope.Close(ret);
      }
      return Local<Value>();
   }
Пример #26
0
   Handle<Script> ScriptSystem::GetScriptFromFile(const std::string& path)
   {
     
      std::string code;
      bool success = GetFileContents(path, code);
      if(!success)
      {
         LOG_ERROR("Could not load script file from " + path);
         return Handle<Script>();
      }

      HandleScope handle_scope;
      Context::Scope context_scope(GetGlobalContext());
      TryCatch try_catch;
      Local<Script> compiled_script = Script::Compile(ToJSString(code), ToJSString(path));

      if(try_catch.HasCaught())
      {
         ReportException(&try_catch);
         return Handle<Script>();
      }

      return handle_scope.Close(compiled_script);
   }
EGLBoolean EGLAPIENTRY Terminate(EGLDisplay dpy)
{
    EVENT("(EGLDisplay dpy = 0x%0.8p)", dpy);

    Display *display = static_cast<Display *>(dpy);
    if (dpy == EGL_NO_DISPLAY || !Display::isValidDisplay(display))
    {
        SetGlobalError(Error(EGL_BAD_DISPLAY));
        return EGL_FALSE;
    }

    gl::Context *context = GetGlobalContext();

    if (display->isValidContext(context))
    {
        SetGlobalContext(NULL);
        SetGlobalDisplay(NULL);
    }

    display->terminate();

    SetGlobalError(Error(EGL_SUCCESS));
    return EGL_TRUE;
}
Пример #28
0
OptionsState::OptionsState(){
	mNormalTextColor = sf::Color(25, 71, 131);
	mSelectedTextColor = sf::Color(255, 255, 255);

	FontManager::FontPtr font = GetGlobalContext().fontManager->Get("BattleCity.ttf;52");

	mTitle.SetText("Options");
	mTitle.SetFont(*font);
	mTitle.SetSize(42);
	mTitle.SetColor(mNormalTextColor);
	mTitle.Move(150, 20);

	mOptions[OPTION_MUSIC].SetText("Music");
	mOptions[OPTION_MUSIC].SetFont(*font);
	mOptions[OPTION_MUSIC].SetSize(24);
	//mOptions[OPTION_MUSIC].SetColor(mNormalTextColor);
	mOptions[OPTION_MUSIC].Move(20, 100);

	//mOptionValues[OPTION_MUSIC].SetText();
	mOptionValues[OPTION_MUSIC].SetFont(*font);
	mOptionValues[OPTION_MUSIC].SetSize(24);
	//mOptionValues[OPTION_MUSIC].SetColor(mNormalTextColor);
	mOptionValues[OPTION_MUSIC].Move(500, 100);

	mOptions[OPTION_SOUND].SetText("Sound");
	mOptions[OPTION_SOUND].SetFont(*font);
	mOptions[OPTION_SOUND].SetSize(24);
	//mOptions[OPTION_MUSIC].SetColor(mNormalTextColor);
	mOptions[OPTION_SOUND].Move(20, 140);

	//mOptionValues[OPTION_MUSIC].SetText();
	mOptionValues[OPTION_SOUND].SetFont(*font);
	mOptionValues[OPTION_SOUND].SetSize(24);
	//mOptionValues[OPTION_MUSIC].SetColor(mNormalTextColor);
	mOptionValues[OPTION_SOUND].Move(500, 140);
}
EGLBoolean EGLAPIENTRY MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
{
    EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface draw = 0x%0.8p, EGLSurface read = 0x%0.8p, EGLContext ctx = 0x%0.8p)",
          dpy, draw, read, ctx);

    Display *display = static_cast<Display*>(dpy);
    gl::Context *context = static_cast<gl::Context*>(ctx);

    // If ctx is EGL_NO_CONTEXT and either draw or read are not EGL_NO_SURFACE, an EGL_BAD_MATCH
    // error is generated.
    if (ctx == EGL_NO_CONTEXT && (draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE))
    {
        SetGlobalError(Error(EGL_BAD_MATCH));
        return EGL_FALSE;
    }

    if (ctx != EGL_NO_CONTEXT && draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE)
    {
        SetGlobalError(Error(EGL_BAD_MATCH));
        return EGL_FALSE;
    }

    // If either of draw or read is a valid surface and the other is EGL_NO_SURFACE, an
    // EGL_BAD_MATCH error is generated.
    if ((read == EGL_NO_SURFACE) != (draw == EGL_NO_SURFACE))
    {
        SetGlobalError(Error(
            EGL_BAD_MATCH, "read and draw must both be valid surfaces, or both be EGL_NO_SURFACE"));
        return EGL_FALSE;
    }

    if (dpy == EGL_NO_DISPLAY || !Display::isValidDisplay(display))
    {
        SetGlobalError(Error(EGL_BAD_DISPLAY, "'dpy' not a valid EGLDisplay handle"));
        return EGL_FALSE;
    }

    // EGL 1.5 spec: dpy can be uninitialized if all other parameters are null
    if (!display->isInitialized() && (ctx != EGL_NO_CONTEXT || draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE))
    {
        SetGlobalError(Error(EGL_NOT_INITIALIZED, "'dpy' not initialized"));
        return EGL_FALSE;
    }

    if (ctx != EGL_NO_CONTEXT)
    {
        Error error = ValidateContext(display, context);
        if (error.isError())
        {
            SetGlobalError(error);
            return EGL_FALSE;
        }
    }

    if (display->isInitialized())
    {
        if (display->testDeviceLost())
        {
            display->notifyDeviceLost();
            return EGL_FALSE;
        }

        if (display->isDeviceLost())
        {
            SetGlobalError(Error(EGL_CONTEXT_LOST));
            return EGL_FALSE;
        }
    }

    Surface *drawSurface = static_cast<Surface*>(draw);
    if (draw != EGL_NO_SURFACE)
    {
        Error error = ValidateSurface(display, drawSurface);
        if (error.isError())
        {
            SetGlobalError(error);
            return EGL_FALSE;
        }
    }

    Surface *readSurface = static_cast<Surface*>(read);
    if (read != EGL_NO_SURFACE)
    {
        Error error = ValidateSurface(display, readSurface);
        if (error.isError())
        {
            SetGlobalError(error);
            return EGL_FALSE;
        }
    }

    if (readSurface)
    {
        Error readCompatError = ValidateCompatibleConfigs(readSurface->getConfig(), context->getConfig(), readSurface->getType());
        if (readCompatError.isError())
        {
            SetGlobalError(readCompatError);
            return EGL_FALSE;
        }
    }

    if (draw != read)
    {
        UNIMPLEMENTED();   // FIXME

        if (drawSurface)
        {
            Error drawCompatError = ValidateCompatibleConfigs(drawSurface->getConfig(), context->getConfig(), drawSurface->getType());
            if (drawCompatError.isError())
            {
                SetGlobalError(drawCompatError);
                return EGL_FALSE;
            }
        }
    }

    Error makeCurrentError = display->makeCurrent(drawSurface, readSurface, context);
    if (makeCurrentError.isError())
    {
        SetGlobalError(makeCurrentError);
        return EGL_FALSE;
    }

    gl::Context *previousContext = GetGlobalContext();

    SetGlobalDisplay(display);
    SetGlobalDrawSurface(drawSurface);
    SetGlobalReadSurface(readSurface);
    SetGlobalContext(context);

    // Release the surface from the previously-current context, to allow
    // destroyed surfaces to delete themselves.
    if (previousContext != nullptr && context != previousContext)
    {
        previousContext->releaseSurface();
    }

    SetGlobalError(Error(EGL_SUCCESS));
    return EGL_TRUE;
}
Пример #30
0
EGLBoolean EGLAPIENTRY MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
{
    EVENT("(EGLDisplay dpy = 0x%0.8p, EGLSurface draw = 0x%0.8p, EGLSurface read = 0x%0.8p, EGLContext ctx = 0x%0.8p)",
          dpy, draw, read, ctx);

    Display *display = static_cast<Display*>(dpy);
    gl::Context *context = static_cast<gl::Context*>(ctx);

    bool noContext = (ctx == EGL_NO_CONTEXT);
    bool noSurface = (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE);
    if (noContext != noSurface)
    {
        SetGlobalError(Error(EGL_BAD_MATCH));
        return EGL_FALSE;
    }

    if (dpy == EGL_NO_DISPLAY)
    {
        SetGlobalError(Error(EGL_BAD_DISPLAY, "'dpy' not a valid EGLDisplay handle"));
        return EGL_FALSE;
    }

    // EGL 1.5 spec: dpy can be uninitialized if all other parameters are null
    if (dpy != EGL_NO_DISPLAY && !display->isInitialized() &&
        (ctx != EGL_NO_CONTEXT || draw != EGL_NO_SURFACE || read != EGL_NO_SURFACE))
    {
        SetGlobalError(Error(EGL_NOT_INITIALIZED, "'dpy' not initialized"));
        return EGL_FALSE;
    }

    if (ctx != EGL_NO_CONTEXT)
    {
        Error error = ValidateContext(display, context);
        if (error.isError())
        {
            SetGlobalError(error);
            return EGL_FALSE;
        }
    }

    if (dpy != EGL_NO_DISPLAY && display->isInitialized())
    {
        if (display->testDeviceLost())
        {
            display->notifyDeviceLost();
            return EGL_FALSE;
        }

        if (display->isDeviceLost())
        {
            SetGlobalError(Error(EGL_CONTEXT_LOST));
            return EGL_FALSE;
        }
    }

    Surface *drawSurface = static_cast<Surface*>(draw);
    if (draw != EGL_NO_SURFACE)
    {
        Error error = ValidateSurface(display, drawSurface);
        if (error.isError())
        {
            SetGlobalError(error);
            return EGL_FALSE;
        }
    }

    Surface *readSurface = static_cast<Surface*>(read);
    if (read != EGL_NO_SURFACE)
    {
        Error error = ValidateSurface(display, readSurface);
        if (error.isError())
        {
            SetGlobalError(error);
            return EGL_FALSE;
        }
    }

    if (draw != read)
    {
        UNIMPLEMENTED();   // FIXME
    }

    gl::Context *previousContext = GetGlobalContext();

    SetGlobalDisplay(display);
    SetGlobalDrawSurface(drawSurface);
    SetGlobalReadSurface(readSurface);
    SetGlobalContext(context);

    display->makeCurrent(drawSurface, readSurface, context);

    // Release the surface from the previously-current context, to allow
    // destroyed surfaces to delete themselves.
    if (previousContext != nullptr && context != previousContext)
    {
        previousContext->releaseSurface();
    }

    SetGlobalError(Error(EGL_SUCCESS));
    return EGL_TRUE;
}