Windows 8 Metro Style apps can either use XAML as I discussed before, or they can use DirectX. This is great for Delphi because our in our newest framework FireMonkey the canvas is powered by DirectX on Windows platforms. So once we can create a DirectX, we should be able to turn that into a FireMonkey canvas, and the full power of FireMonkey should be available to the Metro Style application.
Let's look at what Visual Studio generates when you specify a new DirectX application, and try to recreate that with Delphi. Earlier I looked into creating an application using Windows.UI.Xaml. Application, but in order to use DirectX, you must activate the lower level Windows.ApplicationModel.Core.CoreApplication class, and construct your graphics device and surface from the ground up.
As an aside, internally, the Xaml Application has a CoreApplication as well. At //build/, Matt Merry gave a talk on
Windows Runtime internals: understanding "Hello World" where he shows the internals of a simple hello world Xaml application, debugging down to the CoreApplication level. This is a must watch talk if you want to truly understand the inner workings of a WinRT application.
Back to Delphi. Like my first post about Xaml, this is all pretty rough and I don't think the code is ready to share as a complete project. But I'll discuss the finer points of most of it.
procedure Main;
var
insp: IInspectable;
factory: TViewProviderFactory;
begin
Set8087CW($133f); // Because we're using DirectX, disable all FPU exceptions
factory := TViewProviderFactory.Create;
OleCheck(RoGetActivationFactory(TWindowsString(SCoreApplication), ICoreApplicationInitialization, insp));
(insp as ICoreApplicationInitialization).Run(factory);
end;
There's a bit of a difference here between the Xaml application and this one. Here, we're accessing ICoreApplicationInitialization from Windows.ApplicationModel.Core.CoreApplication. ICoreApplicationInitialization represents a set of static methods that is available for this class -- there is no instance of the CoreApplication object. Instead, we just need to provide the CoreApplication class with a IViewProviderFactory which knows how to create a runnable view. My implementation of IViewProviderFactory is simple:
type
TViewProviderFactory = class(TInspectableObject, IViewProviderFactory)
function CreateViewProvider: IViewProvider; safecall;
end;
{ TViewProviderFactory }
function TViewProviderFactory.CreateViewProvider: IViewProvider;
begin
Result := TViewProvider.Create as IViewProvider;
end;
The ViewProvider is also pretty boilerplate:
type
TActivationEntryPoint = ( Unknown, DirectXApplication );
TViewProvider = class(TInspectableObject, IViewProvider)
private
FWindow: ICoreWindow;
FView: ICoreApplicationView;
FActivationPoint: TActivationEntryPoint;
public
procedure Initialize(window: ICoreWindow; applicationView: ICoreApplicationView); safecall;
procedure Load(entryPoint: HSTRING); safecall;
procedure Run; safecall;
procedure Uninitialize; safecall;
end;
procedure TViewProvider.Initialize(window: ICoreWindow; applicationView: ICoreApplicationView);
begin
FWindow := window;
FView := applicationView;
FActivationPoint := TActivationEntryPoint.Unknown;
end;
procedure TViewProvider.Load(entryPoint: HSTRING);
begin
if string(entryPoint) = 'DirectXApplication.App' then
self.FActivationPoint := TActivationEntryPoint.DirectXApplication;
end;
procedure TViewProvider.Run;
var
View: TD3DView;
begin
if FActivationPoint = TActivationEntryPoint.DirectXApplication then
begin
View := TD3DView.Create(FWindow, FView);
try
View.Run;
finally
View.Free;
end;
end;
end;
Once the application successfully gets a ViewProvider, It calls it's Initialize providing a Window and an ApplicationView. It then calls Load, specifying an entryPoint. This entry point is associated with
Windows Application Contracts, and for now we're just looking at the launch contract. The entry point for the launch contract is going to be the entry point you specified in your appxmanifest, in the Application node. Here I've specified 'DirectXApplication.App'. After it's been Loaded, Run gets called, and we construct and run a View.
type
TD3DView = class(TInspectableObject)
private
FWindow: ICoreWindow;
FView: ICoreApplicationView;
FRenderer: TD3DRender;
public
constructor Create(window: ICoreWindow; applicationView: ICoreApplicationView);
procedure Run;
procedure OnResize(sender: ICoreWindow; args: IWindowSizeChangedEventArgs);
procedure OnDpiChanged(sender: IInspectable);
end;
constructor TD3DView.Create(window: Windows_UI_Core_ICoreWindow;
applicationView: Windows_ApplicationModel_Core_ICoreApplicationView);
var
insp: IInspectable;
begin
FWindow := window;
FView := applicationView;
// The default mouse cursor is the busy wait cursor, switch to a normal pointer.
RoGetActivationFactory(TWindowsString(SCoreCursor), ICoreResourceFactory, insp);
FWindow.PointerCursor := (insp as ICoreResourceFactory).CreateCursor(CoreCursorType.Arrow, 0);
// Hookup events to update display if the Window size changes or the DPI changes
FWindow.add_SizeChanged(TResizeHandler.Create(Self.OnResize));
RoGetActivationFactory(TWindowsString(SDisplayProperties), IDisplayPropertiesStatics, insp);
(insp as IDisplayPropertiesStatics).add_LogicalDpiChanged(TLogicalDpiChangedHandler.Create(OnDpiChanged));
// Create a D3D render target
FRenderer := TD3DRender.Create(FWindow);
end;
procedure TD3DView.Run;
var
Timer: TStopwatch;
lastTime, currentTime, frequency: Int64;
timeTotal, timeDelta: single;
insp: IInspectable;
begin
FWindow.Activate;
RoGetActivationFactory(TWindowsString(SDisplayProperties), IDisplayPropertiesStatics, insp);
FRenderer.SetDPI( (insp as IDisplayPropertiesStatics).LogicalDpi );
Timer := TStopwatch.StartNew;
lastTime := 0;
frequency := TStopwatch.Frequency;
while True do
begin
currentTime := Timer.ElapsedTicks;
timeTotal := (currentTime) / frequency;
timeDelta := (currentTime - lastTime) / frequency;
lastTime := currentTime;
FWindow.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent);
FRenderer.Update( timeTotal, timeDelta);
FRenderer.Render;
end;
end;
Here we see that the view plays a similar role as a message loop in a Win32 application. As long as we're running, we tell the application to process events that have occurred, update the render target, and finally present it to the screen. Here I'm using
System.Diagnostics.TStopwatch to notify the render target how long it has been since the last update. Microsoft's DirectX Application template does something similar with QueryPerformanceCounter, which is actually the same thing TStopwatch does behind the scenes, although TStopwatch has the benefits of falling back on lower resolution timers if no high resolution is available, and it is available cross platform. It might be useful in your apps as well.
The details of my TD3DRender are pretty standard Direct3D calls, create a device, render target, back buffer stencil, swap chain, back buffer texture, and the only painting I'm doing is clearing to blue. The code is essentially a direct translation of everything in the Visual Studio's template D3DRenderer.cpp, and I don't think it adds anything by including it here. The only new thing is there's a new method on IDXGIFactory2 for D3D11,
CreateSwapChainForImmersiveWindow. In Metro Style apps, you don't have access to Window handles, so we can't create the render target in with the usual arguments; instead we have to specify the IWindow.
With that, I have a DirectX application written in Delphi. One thing I noticed is I cannot run it as a normal executable the way I could with the XAML application I made. The call to Windows.ApplicationModel.Infrastructure.CoreApplication.Run(factory) fails with HRESULT $80004005, "Unspecified error". I'm not sure what happens differently when running from the Desktop, but I assume there is some initialization that doesn't happen. So in order to actually run this, I had to package and install it. I suspect it might be related to new compiler/linker features being needed for Windows 8. csc.exe and cl.exe both have new options specific for Windows8. "/t:appcontainerexe" to build an Appcontainer executable makes me think there might be something different they're linking in as a hint to Explorer; that's clearly not something the Delphi compiler is doing but something we need to investigate.
This comment has been removed by the author.
ReplyDeleteGreat Article
DeleteFinal Year Projects for CSE
JavaScript Training in Chennai
Project Centers in Chennai For CSE
JavaScript Training in Chennai
Well done , Nice article .I heard that WinRT native UI controls cannot be used with Direct X apps(At least until now).I feel if we go behind DirectX we may need to lose many features of Metro UI.
ReplyDeleteAgain, well done for your involvement in Delphi and WinRT
By "native UI controls" you mean the XAML controls? Check out my older posts on the viability of Delphi using and consuming XAML based Metro UIs, it's very possible.
ReplyDeleteI think you should be able to create a XAML view and a DirectX view in the same application and swap between them (don't quote me on that :-) ), but yes they are mainly mutually exclusive. The reason DirectX is interesting to Delphi is because DirectX backs FireMonkey, and the features from FireMonkey would then be available to you.
And thanks for the feedback!
i like your article :) , Agen Bola Terpercaya
ReplyDeleteWow, such a big and detailed instruction, very like such things! Yesterday I tried to do like u wrote, and fortunately I could fixed my problem! Thanks a lot, and in return I would like to recommend u one nice site https://yumdownload.com/directx where u can always find only the best versions of all soft including DirectX!
ReplyDeleteis very fond of this article because it gives a lot of inspiration thanks poker online
ReplyDeleteis very fond of this article because it gives a lot of inspiration thanks poker online
ReplyDeleteGames entered our life very quickly, with the help of games, we can immerse ourselves in the virtual world and for a few hours forget about our problems and bad mood. But still there are times when after the installation of the game there are various problems. It happens that sometimes there is not enough of a file to run the game. One of the most common problems when there are not enough files for the DirectX game library. One of the most common errors is an error when there is no d3dx9_43.dll and this error does not allow the game or application to start. This file allows you to enable some graphics accelerator functions (Graphics Card). Eliminate this error is simple enough and does not take much time, just download the d3dx9_43.dll missing https://fix4dll.com/d3dx9_43_dll file to your computer and install it in the correct folder. You can download this dll-library from website completely free of charge.
ReplyDeletethis is really nice and effective blog, i found lots of information in this blog and sites for commenting is best.Very nice I like a lot of these topics... Packers and Movers Kolkata
ReplyDeleteThanks for letting me share
ReplyDeleteTechfogg
Myskyflorist
Avriq
ReplyDeleteAvriq MAP
CCTV Camera
Pest control services
PC Optimization
CP Plus
Termite control services
Avriq
ReplyDeleteThank you for update information. i like your blog
مصبغة غسيل سجاد الكويت
شركة تنظيف منازل الكويت
شحن من الكويت لمصر
فني كهربائي منازل الكويت حولي الفروانية المنطقة العاشرة
شركة الفا لنقل العفش
ReplyDeleteشركة نقل اثاث بجدة
شركة نقل اثاث بالمدينة المنورة
شركة نقل اثاث بالرياض
شركة نقل اثاث بالدمام
شركة نقل اثاث بالطائف
شركة نقل اثاث بمكة
You’ve written nice post, I am gonna bookmark this page, thanks for info. I actually appreciate your own position and I will be sure to come back here.MenmyshopCar StereoDouble Din Android PlayerHyepersonic Double Din PlayerHyundai Creta Double Din Player
ReplyDeleteHyundai Xcent OEM Double Din PlayerbanzaraAdj online
good truth or dare questions
ReplyDeleteAmazing Questions to ask a Girl
awkward would you rather questions
Packers And Movers Bangalore Local Household Shifting Service, Get Free Best Price Quotes Local Packers and Movers in Bangalore List , Compare Charges, Save Money And Time @ Packers And Movers in Bangalore
ReplyDeletePackers and Movers Chennai Give Safe and Reliable ***Household Shifting Services in Chennai with Reasonable ###Packers and Movers Price Quotation. We Provide Household Shifting, Office Relocation, ✔✔✔Local and Domestic Transportation Services, Affordable and Reliable Shifting Service Charges @
ReplyDeletePackers And Movers Chennai
Hire Best Packers And Movers Mumbai for hassle-free Household Shifting, ***Office Relocation, ###Car Transporation, Loading Unloading, packing Unpacking at affordable ✔✔✔ Price Quotation. Top Rated, Safe and Secure Service Providers who can help you with 24x7 and make sure a Untroubled Relocation Services at Cheapest/Lowest Rate
ReplyDeletePackers And Movers Mumbai
Packers And Movers Mumbai to Bhopal
ReplyDeletePackers And Movers Mumbai to Lucknow
Packers And Movers Mumbai to Chandigarh
Packers And Movers Mumbai to Patna
Get Packers and Movers Jaipur List of Top Reliable, 100% Affordable, Verified and Secured Service Provider. Get Free ###Packers and Movers Jaipur Price Quotation instantly and Save Cost and Time. Packers and Movers Jaipur ✔✔✔Reviews and Compare Charges for household Shifting, Home/Office Relocation, ***Car Transportation, Pet Relocation, Bike SHifting @
ReplyDeletePackers And Movers Jaipur
Packers and Movers Gurgaon Provide Reliable, Safe and Certified Service Provider list, Get Free ***Best Price Quotaition and Compare Charges. ✔✔✔ Hassle free Household Shifting Services, High Quality packing Material, Office Relocation, Car Transportaion, ###Local and Domestic Shifting Service @
ReplyDeletePackers And Movers Gurgaon
Every product is especially designed to give every office employee or other customers a comfortable sitting posture without any back pain.
ReplyDeleteOur products can also be customized according to a client’s requirement.
So, the next time you go to shop for sofas, tables or chairs though it be for any purpose don’t forget to have a look at our beautifully designed range of products.
Though we manufacture different products but among all office furniture chairs are the most demanded. We not only deal with local clients but also with national and international clients. The products that we manufacture are supplied to various offices, hospitals, auditoriums, cafeteria, homes and schools. The one reason for being the best office chairs suppliers is due to the durable, economic, comfortable and cost-effective products it manufactures. Our company is so well equipped and makes use of latest technology that it is able to manufacture more than 5,000 chairs every year.
Chair Manufacturers in Mumbai
Chair Supplier in Mumbai
Office Chair Supplier in Mumbai
Visitor Chair Supplier in Mumbai
Chair Dealers in Mumbai
Top Chair Manufacturers in Mumbai
Best Chair Manufacturers in Mumbai
With the modification in the economic state of affairs, factors like globalization of markets, international economic amalgamation, reduced obstacles to business and trade and increase in competition have given rise to the requirement of transportation. It has become one of the most vital infrastructural essential for the expansion of business in today’s era.
ReplyDeletePackers and Movers in Gachibowli
Packers and Movers in Kukatpally
Indian Packers and Movers in Mumbai give packing and moving services like loading & unloading, packing & unpacking, car carriers, transportation, domestic &local shifting, international shifting, Industrial shifting, corporate shifting, Warehousing, etc. Packers and Movers in Mumbai achieve conceit in offering great packing and moving services at reasonable costs. We deal all types of packing and moving services in Mumbai and other main cities of India.
Packers and Movers in KhargharPackers and Movers in Jogeshwari
Packers and Movers in Kharghar
Packers and Movers in Dombivli
Packers and Movers in Thane West
ReplyDeleteشركة غسيل خزانات مياه الشرب بالرياض
https://www.bfirstseo.com/ِشركة-مكافحة-حشرات-بينبع/
https://www.bfirstseo.com/شركة-تنظيف-بينبع/
\
visit to our website for Hp printers help
ReplyDeleteHP Printer support phone number
hp printer customer care number
hp printer technical support number
hp service centre USA
hp store contact number
hp service centre near me
HP Printer tech support phone number USA
For insects and rodents to collect them are the main sources of attraction insects
ReplyDeleteThen the insects invade the entire house.
شركة رش مبيدات
شركة مكافحة النمل الابيض بابها
شركة مكافحة حشرات بابها
شركة رش مبيدات بابها
We are popular as Florist Service in Gurgaon from last 10 Years, we also offers fresh flowers cakes and latest gifts across Gurgaon. Send flowers online and Offline from flower shop for your loved ones and available for corporate gifting with fastest delivery.
ReplyDeleteFlorist Service in Gurgaon
Online Florist Services in Gurgaon
packers and movers baner
packers and movers balewadi
packers and movers ravet
packers and movers bhosari
packers and movers telegaon
packers and movers magarpatta
packers and movers aundh
Packers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ✔✔✔Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges @ Packers And Movers Bangalore
ReplyDeleteNice post!..good information,it is really helpful..it really impressed me alot and i just loved it.Thanks for posting such an informative content: @
ReplyDeletePackers And Movers Mumbai
The Most Reliable Packers And Movers Bangalore And Trusted Partners For All Your Packing,
ReplyDeleteShifting And Relocation Services: Packers and Movers Shifting Services in Bangalore helps you relocate to and from Bangalore,
within city, Interstate, domestic and International destinations. Absolutely stress and Hassle-free Shifting Services in Bangalore.
As part of our services, we also offer a host of other complimentary relocation services designed to meet both individuals specific
moving and relocating needs and companys corporate relocation objectives. We are the best local option for Shifting, domestic Shifting, Household packing, Commercial movement, Vehicle transportation in Bangalore and all that you wish to relocate. @ Packers And Movers Bangalore
Packers and Movers Ahmedabad - We Provide ***Best Service Providers, Safe, Reliable, Affordable, Trusted ###Movers and Packers in Ahmedabad List, Household Shifting, Office Relocation: Choose Top Verified Packers and Movers Ahmedabad Compare ???Shifting Service Chrages, Price Quotation, Rate List Charts and Save Money and Time @ Packers and Movers Ahmedabad
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSuperb post, we enjoyed each and everything as per written in your post. Thank you for this informative article because it’s really helpful, I really like site.
ReplyDeletePlease visit our website: @ Packers and Movers Kolkata
Packers And Movers Ameerpet
ReplyDeletePackers And Movers Chandanagar
Packers And Movers Miyapur
Packers And Movers mehdipatnam
Packers And Movers KPHB Colony
You may know Hotmail is one of the most used email service with 1 billion users. With a Hotmail account, you also have an Microsoft account that give you permission to access all products: Microsoft apps store, Windows, Skype, Outlook.com... without signing up again with hotmail com login
ReplyDeleteSuch a beneficial article. Your article is very interesting, and I really enjoyed it. I would like to thank you for the efforts you had made for writing this awesome article for more related topic on COVID 19 Awareness Wall Sticker Printing
ReplyDeleteNice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.# @ Packers and Movers Kolkata
ReplyDeleteWe Provide Local Packers And Movers Pune List for Get Best Price Quotes, Compare Charges, Save Money And Time, Top Household Shifting Services @ Packers And Movers Pune
ReplyDeleteWe empower you to make better decision when hiring moving and storage services in India. Without any cost to you, we give you the opportunity to compare quotations from up to three different movers and packers available near you.
ReplyDeletepackers and movers in Bangalore
packers and movers in Chennai
packers and movers in Delhi
packers and movers in Faridabad
packers and movers in Ghaziabad
packers and movers in Gurgaon
packers and movers in Hyderabad
packers and movers in Kolkata
packers and movers in Mumbai
packers and movers in Noida
packers and movers service in India
Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.# @ Packers and Movers Ahmedabad
ReplyDeleteThis is really attentiongrabbing, You're a very professional blogger. I have joined your rss feed and sit up for in search of extra of your fantastic post. @ Packers And Movers Bangalore
ReplyDeleteMua vé máy bay tại Aivivu, tham khảo
ReplyDeleteMáy bay từ Hàn Quốc về Việt Nam
bay hà nội hồ chí minh
bảng giá vé máy bay sài gòn hà nội
vé máy bay đi đà lạt vietnam airline
chuyến bay hồi hương từ mỹ về việt nam