DirectX-based adaptive 3D rendering method
By dynamically adjusting the application of metanode storage space and capturing device loss errors in DirectX, the problem of display node storage space not adaptive application and device loss in DirectX is solved, and the effect of normal 3D rendering is achieved after a long time of standby.
Patent Information
- Application Number
- CN202510219222.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-26
- Publication Date
- 2025-06-06
AI Technical Summary
The node storage space in DirectX is not adaptively applied according to the model node size, and there is a problem of loss of the device used for rendering after a long period of locking the screen.
It provides an adaptive 3D rendering method based on DirectX. By dynamically adjusting the application of metanode storage space, applying for cache space according to the metanode changes of the model, and capturing Device loss errors in the rendering loop, and re-initializing Device to ensure the continuity of 3D rendering.
Effectively utilize limited memory space to ensure that 3D rendering can be performed normally after long standby and lock screen, improve the friendliness of the software system, and avoid system crashes caused by 3D rendering errors.
Smart Images

Figure CN120107436A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of 3D scene rendering, and in particular relates to an adaptive 3D rendering method based on DirectX. Background Art
[0002] DirectX is an engine developed by Microsoft for 3D rendering. Developers can develop 3D visual display systems that meet their own needs based on DirectX, but users have some problems when using it for 3D rendering: 1. Display node storage space is not adaptively applied according to the model node size; 2. The device used for rendering may be lost after the screen is locked for a long time. Summary of the invention
[0003] In order to solve the problems raised in the above background technology, the present invention provides an adaptive 3D rendering method based on DirectX to solve the problems that the display node storage space in DirectX is not adaptively applied according to the model node size and the Device used for rendering is lost after the screen is locked for a long time.
[0004] To achieve the above object, the present invention provides the following technical solutions: A DirectX-based adaptive 3D rendering method comprises the following steps: S1: Initialize the graphics device Device; S2: Read the meta-node coordinates of the total surface of the model to be rendered in 3D, and obtain the total number of meta-nodes of the model; S3: According to the total number of meta nodes, apply for the cache space for 3D rendering of the visual model. The size of the cache space is three times the total number of meta nodes. S4: Set the rendering flag of the scene model to be valid, start the rendering loop function Render in the rendering window display function Shown of the scene model, and perform real-time 3D rendering of the model that needs 3D rendering. If the rendered meta-node needs to be added or deleted during the 3D rendering process, return to S2. If the rendered graphics device Device is lost during long-term standby and screen lock, enter S5; S5: Use the error capture function to capture the error of the graphics device Device. After capturing the error, set the rendering flag to invalid, stop the rendering cycle, and wait for the rendering window to regain focus. When awakened, enter S1 in the rendering window drawing function Paint.
[0005] Preferably, the initialization in S1 is to instantiate the graphics device Device and specify a form control for graphics display.
[0006] Preferably, in S2, DirectX uses a triangular face rendering method to split the outer surface of the model to be rendered in 3D into n A triangular face has three vertices. The number of face nodes of a model that needs 3D rendering is 3. n .
[0007] Preferably, each vertex of the triangle element has three variables, namely the three-dimensional coordinates of the vertex, the normal vector and the color.
[0008] Compared with the prior art, the present invention has the following beneficial effects: This application makes corresponding optimizations based on the existing DirectX rendering framework and proposes an adaptive 3D rendering method based on DirectX. This application dynamically adjusts the application for meta-node storage space according to the meta-node changes of the required display model, makes full use of the limited memory space, captures the graphics device Device loss error in the rendering loop, and when the rendering window is reactivated, calls the initialization function to reinitialize the graphics device Device and start 3D rendering. This application can ensure that 3D rendering can be performed normally after long-term standby and screen lock, thereby improving the friendliness of the software system. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1 This is a flowchart of the application; Figure 2 It is a schematic diagram of a meta-node; Figure 3 Schematic diagram of the triangle face node parameter composition. DETAILED DESCRIPTION
[0010] In order to facilitate those skilled in the art to understand the technical content of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific examples. It should be understood that the specific examples described herein are only used to explain the present invention and are not used to limit the present invention.
[0011] Example 1 An adaptive 3D rendering method based on DirectX, such as Figure 1 As shown, the following steps are included: S1: Graphics device Device is the entity handle for DirectX to perform 3D rendering. First, initialize the graphics device Device, mainly instantiate the graphics device Device, specify the form control for graphics display, and display the graphics in the Panel control or PictureBox control. The instantiation code of the graphics device Device is as follows: device = new Direct3D.Device(0, DeviceType.Hardware, this.panel1, CreateFlags.SoftwareVertexProcessing, presentParams); / / Graphics device Device instantiation; S2: Read the node coordinates of the model face to be rendered in 3D, and obtain the number of nodes of the total face of the model; DirectX uses the triangular face rendering method, that is, the outer surface of the model is divided into n A triangular face has three vertices, and the number of face nodes in a model is 3. n ,like Figure 2 As shown in (a), taking a cube as an example, the cube has 6 planes, such as Figure 2 As shown in (b), each plane can be split into 2 triangular face elements, and the surface of the cube can be composed of 12 triangular face elements, so the minimum number of face element nodes of the cube is 12×3.
[0012] S3: Apply for 3D rendering cache space based on the total number of meta-nodes of the model. The cache space size is three times the total number of meta-nodes. like Figure 3 As shown, each vertex of the triangle element has three variables: Position, Normal, and Colored, which are the three-dimensional coordinates, normal vector, and color of the vertex respectively. The specific code is as follows: vertexBuffer=new VertexBuffer(typeof(CustomVertex.PositionNormalColored), n*3, dev, Usage.WriteOnly, CustomVertex.PositionNormalColored.Format, Pool.Default); / / Apply for cache space according to the number of model nodes; S4: Set the rendering flag flag to be valid, start the rendering loop function Render in the rendering window display function Shown, and realize the real-time 3D rendering of the model. The specific code is as follows: private void Form_Shown(object sender, EventArgs e) { while (this.Created && flag) / / Render the model when the flag is valid { this.Render(); / / rendering function } } During the 3D rendering process, if you need to add or delete the rendered model nodes, just enter S2; During the 3D rendering process, after the computer device that carries the rendering task has been in standby mode or locked for a long time, the graphics device Device used for rendering will be lost, causing the 3D rendering to fail to proceed normally. The error capture function is used to capture the graphics device Device loss error, set the rendering flag to invalid, and stop the rendering loop. The specific code is as follows: public void Render() { try{ / / Model rendering...} catch{flag=false;} / / After catching an error, set the flag position to invalid } When the rendering window regains focus and is awakened, enter S1 in the rendering window drawing function Paint, re-initialize the graphics device Device, and re-render the model in 3D. The specific code is as follows: private void Form_target_Paint(object sender, PaintEventArgs e) { if(flag==false) / / If the flag is invalid, reinitialize it and only do it once { / / Graphics device Device instantiation ... / / Get the number of model nodes ... / / Apply for cache space ... flag=true; / / The flag position is valid Form_Shown(null, null) / / Restart model rendering } } This application makes corresponding optimizations based on the existing DirectX rendering framework and proposes an adaptive 3D rendering method based on DirectX. This application dynamically adjusts the application for node storage space according to the node changes of the required display model, makes full use of the limited memory space, captures the Device loss error in the rendering loop, and when the rendering window is reactivated, calls the initialization function to reinitialize the Device and starts 3D rendering, which can ensure that 3D rendering can be performed normally after long-term standby and screen lock, and avoids the software system crashing due to 3D rendering errors.
Claims
1. A DirectX-based adaptive 3D rendering method, characterized in that: The following steps are involved: S1: Initialize the graphics device Device; S2: Read the meta-node coordinates of the total surface of the model to be rendered in 3D, and obtain the total number of meta-nodes of the model; S3: According to the total number of meta nodes, apply for the cache space for 3D rendering of the visual model. The size of the cache space is three times the total number of meta nodes. S4: Set the rendering flag of the scene model to be valid, start the rendering loop function Render in the rendering window display function Shown of the scene model, and perform real-time 3D rendering of the model that needs 3D rendering. If the rendered meta-node needs to be added or deleted during the 3D rendering process, return to S2. If the rendered graphics device Device is lost during long-term standby and screen lock, enter S5; S5: Use the error capture function to capture the error of the graphics device Device. After capturing the error, set the rendering flag to invalid, stop the rendering cycle, and wait for the rendering window to regain focus. When awakened, enter S1 in the rendering window drawing function Paint.
2. The DirectX-based adaptive 3D rendering method according to claim 1, characterized in that: The initialization in S1 is to instantiate the graphics device Device and specify the form controls for graphics display.
3. The DirectX-based adaptive 3D rendering method according to claim 1, characterized in that: In S2, DirectX uses triangular face rendering to split the outer surface of the model to be rendered in 3D into n A triangular face has three vertices. The number of face nodes of a model that needs 3D rendering is 3. n .
4. The DirectX-based adaptive 3D rendering method according to claim 3, characterized in that: Each vertex of a triangle face has three variables, namely the three-dimensional coordinates of the vertex, the normal vector and the color.