Texture rendering method, system, device terminal and storage medium
By obtaining the rendering context handle and shared texture handle in the Unity engine, creating rendering components and binding shared textures, the problem of the inability to share rendering resources in the Unity engine in multi-threaded mode is solved, realizing the high flexibility and scalable rendering capabilities of the native platform.
Patent Information
- Application Number
- CN202511343617.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-19
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2045-09-19
AI Technical Summary
The reason why the Unity engine cannot achieve highly complex and highly interactive visual effects in multi-threaded rendering mode is that rendering resources cannot be directly accessed or shared by the system's native code, which limits the rendering capabilities of the native platform.
By obtaining the rendering context handle and the shared texture handle, rendering components are created, including native surface view classes and native renderers. The lifecycle of the target surface view is monitored, the renderer is instantiated and bound to the shared texture, thus enabling the sharing of rendering resources between the rendering engine and the native platform.
In multi-threaded rendering mode, the limitations of texture data sharing between the rendering engine and the native platform are overcome, improving the flexibility and scalability of the native platform in image rendering.
Smart Images

Figure CN120849005B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a texture rendering method, system, device terminal and storage medium. Background Technology
[0002] With the continuous improvement of mobile device performance and the increasing demand for multimedia experiences from users, how to efficiently display high-quality and diverse graphic content on mobile devices has become an important issue for developers. Unity (rendering engine), with its powerful real-time rendering capabilities and cross-platform publishing support, can be used to realize complex real-time interactive graphics scenes, enabling developers to achieve a good balance between performance and visual effects, thereby achieving smooth and immersive graphics performance on various smart terminals.
[0003] In related technologies, Unity integrates with native components of the device's operating system to create an OpenGLES (Open Graphics Library for Embedded Systems) rendering environment at runtime and perform rendering, presenting scene content on the device view. However, Unity's internal rendering resources cannot be directly accessed or shared by the system's native code, especially in multi-threaded rendering mode. Business logic typically runs on ordinary execution threads rather than rendering threads, making it impossible to share GPU (Graphics Processing Unit) resources through context objects. This limits the ability of native platforms to achieve highly complex and interactive visual effects through Unity. Summary of the Invention
[0004] This application discloses a texture rendering method, system, device terminal, and storage medium to solve the technical problems of monotonous effects and limited use when displaying rendering engine images on the native platform side.
[0005] This application provides a texture rendering method, the method comprising: obtaining a rendering context handle and a shared texture handle, wherein the rendering context handle and the shared texture handle are created by a rendering engine, and the rendering context handle is created by the rendering engine calling a native rendering library; creating a rendering environment that shares a texture with the rendering engine based on the rendering context handle, and creating a rendering component in the rendering environment, wherein the rendering component includes a native surface view class and a native renderer, the native surface view class being used to manage the lifecycle of the surface view, and the native renderer being used to perform texture rendering operations; calling the native surface view class to instantiate the native renderer by monitoring the lifecycle of the target surface view to obtain a rendering instance, and binding the corresponding shared texture to the rendering instance based on the shared texture handle; and rendering the shared texture onto the target surface view through the rendering instance.
[0006] In one embodiment of this application, the rendering engine creates and transmits the rendering context handle and the shared texture handle in the following manner: obtaining an image interface file and a rendering context management library, and constructing the native rendering library based on the image interface file and the rendering context management library; loading the native rendering library in a script file, and calling a rendering event triggering method to trigger a rendering event, so as to obtain the rendering context in the rendering thread and create the rendering context handle; creating a shared texture instance, and obtaining the handle of the shared texture instance to obtain the shared texture handle; and transmitting the rendering context handle and the shared texture handle through a native interface.
[0007] In one embodiment of this application, obtaining the rendering context in the rendering thread includes: in response to the rendering event, calling a rendering event acquisition method to register a rendering event callback function; executing the rendering event callback function in the rendering thread to call a rendering parameter acquisition method to obtain the rendering parameters of the engine rendering environment; and, based on the rendering parameters, calling a rendering context acquisition method provided by the rendering context management library to obtain the rendering context; wherein, the native rendering library includes the rendering event acquisition method and the rendering parameter acquisition method.
[0008] In one embodiment of this application, the step of creating a rendering environment that shares a texture with the rendering engine based on the rendering context handle, and creating a rendering component in the rendering environment, includes: obtaining the rendering context in which the rendering engine resides from the native rendering library based on the rendering context handle, and creating the rendering environment based on the rendering context; in the rendering environment, creating the native surface view class by inheriting from the surface view class in the Java layer, and creating the native renderer in the C++ layer based on the rendering context handle to obtain the rendering component; wherein, the native renderer includes a rendering scheduler class, a rendering management class, and a rendering implementation class, the rendering scheduler class is used to call the rendering management class, the rendering management class is used to manage the rendering instance, and the rendering implementation class is used to render the shared texture.
[0009] In one embodiment of this application, the step of calling the native surface view class to instantiate the native renderer and obtain a rendering instance by supervising the lifecycle of the target surface view includes: instantiating a native surface view object based on the rendering context handle and the shared texture handle, wherein the native surface view object holds a first lifecycle method for managing the target surface view; binding the first lifecycle method to a second lifecycle method held by the rendering scheduler class in the native renderer; initializing a renderer identifier in the native surface view object and calling a rendering instance creation method in the rendering scheduler class based on the renderer identifier; and in the rendering instance creation method, calling the rendering management class in the native renderer to create the rendering instance.
[0010] In one embodiment of this application, binding the corresponding shared texture to the rendering instance based on the shared texture handle includes: calling a texture binding method through the native surface view object to pass the shared texture handle and the renderer identifier to the rendering scheduler class; calling the rendering management class through the rendering scheduler class to locate the rendering instance based on the renderer identifier, and calling a texture setting method through the rendering management class; in the texture setting method, binding the shared texture to the rendering instance based on the shared texture handle.
[0011] In one embodiment of this application, rendering the shared texture onto the target surface view through the rendering instance includes: if there is one shared texture and it is bound to multiple target surface views, then the shared texture is rendered on each of the target surface views; if there are multiple shared textures and they are all bound to the same target surface view, then the multiple shared textures are switched and rendered on the target surface view according to a preset timing sequence; if there are multiple shared textures and multiple target surface views, then the multiple shared textures are rendered on the corresponding bound target surface views according to a preset binding relationship.
[0012] This application also provides a texture rendering system, the system comprising: an acquisition module, configured to acquire a rendering context handle and a shared texture handle, wherein the rendering context handle and the shared texture handle are created by a rendering engine, and the rendering context handle is created by the rendering engine calling a native rendering library; a creation module, configured to create a rendering environment sharing a texture with the rendering engine based on the rendering context handle, and create a rendering component in the rendering environment, wherein the rendering component includes a native surface view class and a native renderer, the native surface view class being used to manage the lifecycle of the surface view, and the native renderer being used to perform texture rendering operations; a binding module, configured to call the native surface view class, instantiate the native renderer by monitoring the lifecycle of the target surface view to obtain a rendering instance, and bind the corresponding shared texture to the rendering instance based on the shared texture handle; and a rendering module, configured to render the shared texture onto the target surface view through the rendering instance.
[0013] This application also provides a device terminal, including: using the texture rendering method as described above, or including the texture rendering system as described above.
[0014] This application also provides a computer-readable storage medium storing computer-readable instructions that, when executed by a computer's processor, cause the computer to perform the texture rendering method described above.
[0015] The beneficial effects of this application are as follows: This application provides a texture rendering method, system, device terminal, and storage medium. First, a rendering context handle and a shared texture handle are obtained. These are created by the rendering engine, with the rendering context handle created by the rendering engine calling the native rendering library. Next, a rendering environment sharing a texture with the rendering engine is created based on the rendering context handle. Then, a rendering component is created within this environment. The rendering component includes a native surface view class and a native renderer. The native surface view class manages the lifecycle of the surface view, and the native renderer performs texture rendering operations. Finally, the native surface view class is called, and the rendering is performed through a monitoring object... The native renderer is instantiated based on the lifecycle of the target surface view to obtain a rendering instance. The corresponding shared texture is then bound to the rendering instance based on the shared texture handle. Finally, the shared texture is rendered on the target surface view through the rendering instance. Based on the GPU resource sharing capability of the rendering context, a shared rendering environment between the rendering engine and the native platform is established according to the rendering context handle and the shared texture handle created by the rendering engine. In multi-threaded rendering mode, the native platform can render and use the shared texture, breaking through the limitation of texture data sharing between the rendering engine and the native platform, thereby improving the flexibility and scalability of the native platform in terms of image rendering. Attached Figure Description
[0016] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0017] In the attached diagram:
[0018] Figure 1 This is a schematic diagram illustrating an implementation environment of a texture rendering system, as shown in an exemplary embodiment of this application.
[0019] Figure 2 This is a flowchart illustrating a texture rendering method in an exemplary embodiment of this application;
[0020] Figure 3 This is a flowchart illustrating a specific texture rendering method as shown in an exemplary embodiment of this application;
[0021] Figure 4 This is a schematic diagram illustrating the structure of a rendering component according to an exemplary embodiment of this application;
[0022] Figure 5 This is a flowchart illustrating a rendering component implementing shared texture rendering, as shown in an exemplary embodiment of this application.
[0023] Figure 6 This is a flowchart illustrating another specific texture rendering method as shown in an exemplary embodiment of this application;
[0024] Figure 7 This is a block diagram illustrating a texture rendering system in an exemplary embodiment of this application;
[0025] Figure 8 This is a schematic diagram of the structure of a device terminal provided in one embodiment of this application. Detailed Implementation
[0026] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0027] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. The drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the shape, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.
[0028] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the present application. However, it will be apparent to those skilled in the art that embodiments of the present application may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the present application.
[0029] Unity integrates with the device's operating system's native components to create an OpenGLES rendering environment and execute rendering at runtime, presenting scene content on the device view. To improve rendering performance, Unity employs a multi-threaded rendering architecture, allowing different threads to handle different logic. For example, thread A handles screen rendering logic, thread B handles business logic, and thread C handles time-consuming file loading. However, the inventors of this application discovered that the content rendered by Unity is output as a whole to a single view, and its internal rendering resources cannot be directly accessed or shared by the system's native code. In multi-threaded rendering mode, business code operates on a normal execution thread, not a rendering thread, and therefore cannot obtain the OpenGLES context object. This prevents the sharing of GPU resources through the OpenGLES context object, limiting the ability of the native platform to achieve highly complex and interactive visual effects using Unity.
[0030] Therefore, please see Figure 1 , Figure 1 This is a schematic diagram illustrating an implementation environment of a texture rendering system, as shown in an exemplary embodiment of this application. Figure 1 As shown, the implementation environment may include a device terminal 100 and a native platform 110 and a rendering engine 120 within the device terminal 100. A texture rendering system 111 can be deployed on the native platform 110 side of the device terminal 100, and in conjunction with the rendering engine 120, implement a texture rendering scheme in the device terminal 100 that shares rendering resources with the native platform side based on an OpenGLES context. The device terminal 100 may be a smartphone, tablet, computer, or in-vehicle system, etc. The native platform 110 includes, but is not limited to, the Android operating system, and the rendering engine 120 may be the Unity engine. The texture rendering system 111, based on the GPU resource sharing capability of the rendering context, establishes a shared rendering environment between the rendering engine and the native platform according to the received rendering context handle and shared texture handle. In multi-threaded rendering mode, the native platform can render and use the shared texture, overcoming the limitations of texture data sharing between the rendering engine and the native platform, thereby improving the flexibility and scalability of the native platform in image rendering.
[0031] Please see Figure 2 , Figure 2 This is a flowchart illustrating a texture rendering method in an exemplary embodiment of this application. This method can be applied to... Figure 1 The implementation environment is shown, and the method is specifically executed by the texture rendering system 111 in that implementation environment. It should be understood that the method can also be applied to other exemplary implementation environments and specifically executed by devices in other implementation environments. This embodiment does not limit the implementation environment to which the method is applicable.
[0032] like Figure 2 As shown, in an exemplary embodiment, the texture rendering method includes at least steps S210 to S240, which are described in detail below:
[0033] Step S210: Obtain the rendering context handle and the shared texture handle, wherein the rendering context handle and the shared texture handle are created by the rendering engine, and the rendering context handle is created by the rendering engine calling the native rendering library.
[0034] Step S220: Create a rendering environment that shares textures with the rendering engine based on the rendering context handle, and create a rendering component in the rendering environment. The rendering component includes a native surface view class and a native renderer. The native surface view class is used to manage the lifecycle of the surface view, and the native renderer is used to perform texture rendering operations.
[0035] Step S230: Invoke the native surface view class, instantiate the native renderer by monitoring the lifecycle of the target surface view, obtain the rendering instance, and bind the corresponding shared texture to the rendering instance according to the shared texture handle.
[0036] Step S240: Render the shared texture onto the target surface view using a rendering instance.
[0037] The rendering engine is the Unity engine; the rendering context handle is a reference or identifier of Unity's current graphics API (Application Programming Interface), such as the rendering context EGLContext used by OpenGLES. The EGLContext contains all rendering-related state information, such as the currently used shader program, bound textures, vertex buffer objects, frame buffer objects, etc., as well as rendering configurations such as rasterization rules, blending modes, and depth testing. Through the rendering context handle, the same rendering context can be accessed in different execution environments to share rendering resources; the shared texture handle is an identifier of a texture object created in Unity that allows cross-process or cross-system access.
[0038] In step S210, when Unity starts, it initializes the graphics API and creates a rendering context to perform rendering operations. Then, it obtains the rendering context by calling the native rendering library, thereby creating a rendering context handle. In order to achieve texture sharing, the rendering context handle and the shared texture handle can be synchronized to the native platform side, so that the native platform obtains the rendering context handle and the shared texture handle.
[0039] In step S220, the obtained rendering context handle is used to create a texture-shared rendering environment, thereby enabling access to texture resources created by Unity, and a rendering component NativeSurfaceView is established in the rendering environment, including the native surface view class NativeSurfaceView and the native renderer NativeSurfaceView.so, to further realize the rendering operation of shared textures.
[0040] In step S230, a rendering instance of the native renderer is created based on the lifecycle of the target view surface using the native surface view class. Then, the texture is bound to the rendering instance using a shared texture handle, enabling the native renderer to directly use texture resources from the Unity side.
[0041] In step S240, based on the rendering instance bound to the shared texture handle, OpenGLES is used to render the shared texture on the target surface view, so as to achieve the purpose of sharing the texture on the Unity side for use by the native platform side for rendering.
[0042] In this embodiment, based on the GPU resource sharing capability of the rendering context, a shared rendering environment is established between the rendering engine and the native platform according to the rendering context handle and the shared texture handle created by the rendering engine. In multi-threaded rendering mode, the native platform can render and use the shared texture, breaking through the limitation of texture data sharing between the rendering engine and the native platform, thereby improving the flexibility and scalability of the native platform in terms of image rendering.
[0043] In one embodiment, the rendering engine creates and passes the rendering context handle and the shared texture handle in the following ways: obtaining an image interface file and a rendering context management library, and constructing a native rendering library based on the image interface file and the rendering context management library; loading the native rendering library in a script file and calling a rendering event triggering method to trigger a rendering event, so as to obtain the rendering context in the rendering thread and create a rendering context handle; creating a shared texture instance and obtaining the handle of the shared texture instance to obtain the shared texture handle; and passing the rendering context handle and the shared texture handle through a native interface.
[0044] In this embodiment, Unity builds a native rendering library, NativeRenderingPlugin.cpp, based on the image interface files and rendering context management library provided by C++ (a programming language). This allows C++ to execute directly in the rendering thread, thus enabling the EGLContext to be obtained in the C++ layer. NativeRenderingPlugin.cpp is included in Unity script files, so it can be loaded within the script files. During script file initialization, the rendering event triggering method GL.IssuePluginEvent provided by Unity is used to trigger rendering events, thereby obtaining the EGLContext in the rendering thread and creating a rendering context handle. Unity creates a shared texture instance, RenderTexture, and obtains the handle of RenderTexture, thus acquiring the shared texture handle. Unity uses the native interface, namely JNI (Java Native Interface, a native interface of Java (a programming language), to call the CreateGLTextureView method in the bridge class that interacts natively with Unity. This method passes the rendering context handle and the shared texture handle to the native platform, allowing the native platform to render and use the shared texture based on the rendering context handle and the shared texture handle.
[0045] In this way, by building a native rendering library, it is possible to obtain the rendering context and create a rendering context handle in the rendering thread, and by combining the JNI mechanism, pass the rendering context handle and the shared texture handle to the native platform, enabling the native platform to render and use the shared texture in multi-threaded rendering mode.
[0046] Please see Figure 3 , Figure 3 This is a flowchart illustrating a specific texture rendering method as shown in an exemplary embodiment of this application. Figure 3 As shown, Unity obtains the EGLContext in the rendering thread based on the built NativeRenderingPlugin.cpp, creates a rendering context handle, creates a shared texture instance, obtains the shared texture handle, and then passes the rendering context handle and the shared texture handle to the native platform based on JNI. The native platform can obtain the EGLContext from NativeRenderingPlugin.cpp based on the rendering context handle, thereby creating a shared rendering environment, and through the built rendering component, combined with the EGLContext and the shared texture handle, obtain the shared texture created by Unity for rendering.
[0047] In one embodiment, obtaining the rendering context in the rendering thread includes: in response to a rendering event, calling a rendering event acquisition method to register a rendering event callback function; executing the rendering event callback function in the rendering thread, calling a rendering parameter acquisition method to obtain the rendering parameters of the engine rendering environment; and, based on the rendering parameters, calling a rendering context acquisition method provided by the rendering context management library to obtain the rendering context; wherein, the native rendering library includes a rendering event acquisition method and a rendering parameter acquisition method.
[0048] In this embodiment, in response to a rendering event, the rendering event acquisition method GetRenderEventFunc in NativeRenderingPlugin.cpp is called to register the rendering event callback function OnRenderEvent, and OnRenderEvent is executed in the rendering thread. The rendering parameter acquisition method GetOpenGLESParameter in NativeRenderingPlugin.cpp is called to obtain the rendering parameters of the Unity rendering environment. Based on the rendering parameters, the rendering context acquisition method eglGetCurrentContext provided by the rendering context management library is called to obtain the rendering context.
[0049] In this way, the reliability of obtaining the rendering context is ensured by obtaining the rendering context through a step-by-step callback method.
[0050] In one embodiment, creating a rendering environment that shares a texture with the rendering engine based on a rendering context handle, and creating a rendering component within the rendering environment, includes: obtaining the rendering context in which the rendering engine resides from the native rendering library based on the rendering context handle, and creating the rendering environment based on the rendering context; in the rendering environment, creating a native surface view class that inherits from the Java layer's surface view class, and creating a native renderer in the C++ layer based on the rendering context handle to obtain the rendering component; wherein, the native renderer includes a rendering scheduler class, a rendering management class, and a rendering implementation class, the rendering scheduler class being used to call the rendering management class, the rendering management class being used to manage rendering instances, and the rendering implementation class being used to render the shared texture.
[0051] In this embodiment, Unity provides NativeRenderingPlugin.cpp based on C++. The native platform uses the rendering context handle to call the shared rendering context creation method createSharedEGLContext in the texture view creation method CreateGLESTextureView to obtain the EGLContext used by Unity, and then creates a rendering environment that shares textures with the rendering engine based on the EGLContext.
[0052] Additionally, please see Figure 4 , Figure 4 This is a schematic diagram illustrating the structure of a rendering component, as shown in an exemplary embodiment of this application. Figure 4 As shown, the rendering component comprises Java and C++ parts. The `NativeSurfaceView` class is implemented in the Java layer, inheriting from the native platform's surface view class `SurfaceView`, and manages the lifecycle of the surface view. `NativeSurfaceView.so` is implemented in the C++ layer, interacting with the Java layer via JNI. `NativeSurfaceView.so` binds to the rendering context handle, sharing texture resources created by Unity. `NativeSurfaceView.so` contains the rendering scheduler class `NativeWithEGL.cpp`, the rendering manager class `RendererManager.cpp`, and the rendering implementation class `Renderer.cpp`. `NativeWithEGL.cpp` is responsible for interacting with the Java layer, calling `RendererManager.cpp` to manage `Renderer.cpp`. `RendererManager.cpp` handles the creation and destruction of rendering instances, while `Renderer.cpp` handles texture rendering. Together, they implement the shared texture rendering operation throughout the surface view's lifecycle. This cross-language collaboration mechanism decouples the Java layer view management from the C++ layer rendering logic, improving code maintainability. Furthermore, the three-layer renderer structure enhances the scalability of the texture rendering logic.
[0053] In this way, a rendering environment with textures shared with the rendering engine is created based on the rendering context handle, and a rendering component containing native surface view classes and native renderers is constructed, realizing the sharing of rendering resources between Unity and the native platform.
[0054] In one embodiment, invoking the native surface view class to instantiate the native renderer by managing the lifecycle of the target surface view and obtaining a rendering instance includes: instantiating a native surface view object based on a rendering context handle and a shared texture handle, wherein the native surface view object holds a first lifecycle method for managing the target surface view; binding the first lifecycle method to a second lifecycle method held by the rendering scheduler class in the native renderer; initializing a renderer identifier in the native surface view object and invoking a rendering instance creation method in the rendering scheduler class based on the renderer identifier; and in the rendering instance creation method, invoking the rendering management class in the native renderer to create a rendering instance.
[0055] The native surface view object NativeSurfaceView.java holds the following first lifecycle methods: surfaceCreated (for initialization and creation), surfaceChanged (for window changes), and surfaceDestroyed (for window destruction). NativeWithEGL.cpp holds the following second lifecycle methods: nativeStartRender (for rendering startup), nativeSurfaceChanged (for adjusting rendering parameters), and nativeSurfaceDestroy (for rendering cleanup). The renderer identifier is used to distinguish between multiple rendering instances when they coexist.
[0056] For example, the first lifecycle methods are bound to the second lifecycle methods held by the rendering dispatch class in the native renderer. Specifically, the `SurfaceCreated` method is bound to `nativeStartRender`, the `surfaceChanged` method to `nativeSurfaceChanged`, and the `surfaceDestroyed` method to `nativeSurfaceDestroyed`. After initialization in `NativeSurfaceView.java`, the `surfaceCreated` method is automatically called, and then the `nativeStartRender` method is called within it. When the window size or other parameters of the surface view corresponding to `NativeSurfaceView.java` change, the `surfaceChanged` method is automatically called, and then the `nativeSurfaceChanged` method is called within it. When the surface view corresponding to `NativeSurfaceView.java` needs to be destroyed, the `surfaceDestroyed` method is actively called, and then the `nativeSurfaceDestroyed` method is called within it.
[0057] In this embodiment, please refer to Figure 5 , Figure 5 This is a flowchart illustrating a rendering component implementing shared texture rendering, as shown in an exemplary embodiment of this application. Figure 5As shown, after instantiating NativeSurfaceView.java, the nativeStartRender method is called to bind the lifecycle, and the initialized renderer identifier is passed to NativeWithEGL.cpp. The renderer instance creation method CreateNativeRenderer in NativeWithEGL.cpp is called according to the renderer identifier. In the CreateNativeRenderer method, RendererManager.cpp is called to create a renderer instance according to the renderer identifier.
[0058] In this way, by establishing a lifecycle binding mechanism between the native surface view class and the rendering scheduler class, the creation process of the rendering instance is synchronized with the state of the surface view.
[0059] In one possible embodiment, please continue to see Figure 5 After the rendering instance is created, Renderer.cpp actively calls the rendering instance callback function OnEGLContextCreateComplete to notify NativeSurfaceView.java that the rendering instance has been created, so that NativeSurfaceView.java can perform texture binding operations.
[0060] In one embodiment, binding a corresponding shared texture to a rendering instance based on a shared texture handle includes: calling a texture binding method through a native surface view object to pass the shared texture handle and renderer identifier to a rendering scheduler class; calling a rendering management class through the rendering scheduler class to locate the rendering instance based on the renderer identifier, and calling a texture setting method through the rendering management class; in the texture setting method, binding the shared texture to the rendering instance based on the shared texture handle.
[0061] Among them, the texture binding method nativeBindTexture and the texture setting method SetMainTex are methods in the C++ layer, and NativeSurfaceView.java implements the calling of the nativeBindTexture method through JNI.
[0062] In this embodiment, please continue to refer to Figure 5After receiving the message that the rendering instance has been created, NativeSurfaceView.java calls the nativeBindTexture method to pass the shared texture handle and renderer identifier to NativeWithEGL.cpp. NativeWithEGL.cpp calls RendererManager.cpp to locate the rendering instance based on the renderer identifier, and RendererManager.cpp calls the SetMainTex method to bind the shared texture to the rendering instance based on the shared texture handle. After the shared texture is bound, the rendering instance will continuously render the shared texture's image during the lifecycle of the corresponding surface view.
[0063] In this way, the efficient binding of shared textures and rendering instances through the hierarchical scheduling mechanism enables the sharing of rendering resources between Unity and the native platform.
[0064] In one embodiment, rendering a shared texture onto a target surface view through a rendering instance includes: if there is one shared texture and it is bound to multiple target surface views, then the shared texture is rendered on each target surface view; if there are multiple shared textures and they are all bound to the same target surface view, then the multiple shared textures are switched and rendered on the target surface view according to a preset timing sequence; if there are multiple shared textures and multiple target surface views, then the multiple shared textures are rendered on the corresponding bound target surface views according to a preset binding relationship.
[0065] The preset binding relationship includes at least one of one-to-one, many-to-one, and one-to-many; the binding between the shared texture and the target surface view can be achieved based on the shared texture handle and the surface view identifier.
[0066] In this embodiment, considering that during the process of rendering shared textures on target surface views, there may be situations where one shared texture corresponds to multiple target surface views, multiple shared textures correspond to one target surface view, or multiple shared textures correspond to different target surface views, a differentiated rendering strategy is adopted.
[0067] For example, in Unity, texture A is the front view of the scene rendered by Unity's main camera A, texture B is the side view of the scene rendered by Unity's secondary camera B, and texture C is the top view of the scene rendered by Unity's secondary camera C. Under normal rendering, where the textures do not share textures, Unity can only render a single image on a target surface view specific to the native platform. However, based on the texture sharing mechanism, it is possible to achieve display effects such as multiple views per single image, single view multiple images, and multiple views multiple images. For example, texture A can be rendered on multiple target surface views, textures A, B, and C can be switched to be rendered on the same target surface view, or textures A and B can be switched to be rendered on one target surface view, and texture C can be rendered on another target surface view.
[0068] For example, parallel rendering of multiple shared textures on different target surface views can be achieved by assigning different rendering instances.
[0069] In this way, based on the texture sharing mechanism, the problem of the limited and monotonous display of Unity images on the native platform is solved, and the diversity of Unity-based display images on the native platform and the scalability of display effects are improved.
[0070] Please see Figure 6 , Figure 6 This is a flowchart illustrating another specific texture rendering method as shown in an exemplary embodiment of this application. For example... Figure 6 As shown, the rendering engine loads the built native rendering library. After the native rendering library is initialized, it obtains the EGLContext to create a rendering context handle, then creates a shared texture instance to obtain a shared texture handle, and passes the rendering context handle and the shared texture handle to the native platform. Upon receiving the rendering context handle and the shared texture handle, the native platform retrieves the EGLContext from the native rendering library based on the rendering context handle to create a rendering environment that shares textures with the rendering engine. Then, it passes the EGLContext and the shared texture handle to the native surface view class in the rendering component, which in turn passes the EGLContext and the shared texture handle to the native rendering library to create a rendering instance. After the rendering instance is created, the shared texture is bound to the rendering instance through the native surface view class. After binding the shared texture, the rendering instance continuously renders the shared texture's image throughout the surface view's lifecycle. This overcomes the limitations of texture data sharing between the rendering engine and the native platform, thereby improving the native platform's flexibility and scalability in image rendering.
[0071] The texture rendering method described above first obtains the rendering context handle and the shared texture handle. These are created by the rendering engine, which in turn calls the native rendering library to create the rendering context handle. Next, a rendering environment sharing the texture with the rendering engine is created based on the rendering context handle. Rendering components are then created within this environment, including a native surface view class and a native renderer. The native surface view class manages the lifecycle of the surface view, while the native renderer performs texture rendering operations. The native surface view class is then invoked, and the native renderer is instantiated by monitoring the lifecycle of the target surface view to obtain a rendering instance. The corresponding shared texture is then bound to the rendering instance based on the shared texture handle. Finally, the shared texture is rendered onto the target surface view using the rendering instance. Leveraging the GPU resource sharing capabilities of the rendering context, and based on the rendering context handle and shared texture handle created by the rendering engine, a shared rendering environment is established between the rendering engine and the native platform. In multi-threaded rendering mode, the native platform can render and use the shared texture, overcoming the limitations of texture data sharing between the rendering engine and the native platform, thereby enhancing the flexibility and scalability of the native platform in image rendering.
[0072] Please see Figure 7 , Figure 7 This is a block diagram illustrating a texture rendering system as shown in an exemplary embodiment of this application. The system can be applied to... Figure 1 The implementation environment shown is intended to illustrate the system, but it should be understood that the system can also be applied to other exemplary implementation environments. This embodiment does not limit the implementation environment to which the system is applicable.
[0073] like Figure 7 As shown, in an exemplary embodiment, the texture rendering system 700 includes at least an acquisition module 710, a creation module 720, a binding module 730, and a rendering module 740, which are described in detail below:
[0074] The module 710 is used to obtain the rendering context handle and the shared texture handle. The rendering context handle and the shared texture handle are created by the rendering engine, and the rendering context handle is created by the rendering engine calling the native rendering library.
[0075] Create module 720 to create a rendering environment that shares textures with the rendering engine based on the rendering context handle, and create rendering components in the rendering environment. The rendering components include a native surface view class and a native renderer. The native surface view class is used to manage the lifecycle of the surface view, and the native renderer is used to perform texture rendering operations.
[0076] The binding module 730 is used to call the native surface view class, instantiate the native renderer by supervising the lifecycle of the target surface view, obtain the rendering instance, and bind the corresponding shared texture to the rendering instance according to the shared texture handle;
[0077] Rendering module 740 is used to render shared textures onto a target surface view using a rendering instance.
[0078] It should be noted that the texture rendering system provided in the above embodiments and the texture rendering method provided in the above embodiments belong to the same concept. The content of the operation performed by each module has been described in detail in the method embodiments, and will not be repeated here.
[0079] This application also provides a device terminal that uses the texture rendering method described above, or includes the texture rendering system described above.
[0080] Please see Figure 8 , Figure 8 This is a schematic diagram of the structure of a device terminal provided in one embodiment of this application. Figure 8 A schematic diagram of a computer system suitable for implementing the device terminal of this application is shown. It should be noted that... Figure 8 The computer system 800 of the device terminal shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0081] like Figure 8 As shown, the computer system 800 includes a Central Processing Unit (CPU) 801, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in Read-Only Memory (ROM) 802 or programs loaded from storage portion 808 into Random Access Memory (RAM) 803. The RAM 803 also stores various programs and data required for system operation. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An Input / Output (I / O) interface 805 is also connected to the bus 804.
[0082] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.
[0083] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs various functions defined in the system of this application.
[0084] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a computer's processor, causes the computer to perform the texture rendering method described above. This computer-readable storage medium may be included in the device terminal described in the above embodiments, or it may exist independently and not deployed within the device terminal.
[0085] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.
[0086] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.
Claims
1. A texture rendering method, characterized in that, The method includes: Obtain a rendering context handle and a shared texture handle, wherein the rendering context handle and the shared texture handle are created by the rendering engine, and the rendering context handle is created by the rendering engine calling the native rendering library, which is a native rendering library implemented in C++; A rendering environment sharing textures with the rendering engine is created based on the rendering context handle, and a rendering component is created in the rendering environment. The rendering component includes a native surface view class and a native renderer. The native surface view class is used to manage the lifecycle of the surface view, and the native renderer is used to perform texture rendering operations. The native surface view class is invoked to instantiate the native renderer by monitoring the lifecycle of the target surface view, obtain a rendering instance, and bind the corresponding shared texture to the rendering instance according to the shared texture handle; The shared texture is rendered onto the target surface view using the rendering instance; The creation of the rendering environment includes: obtaining the rendering context of the rendering engine from the native rendering library according to the rendering context handle, and creating the rendering environment according to the rendering context; the creation of the rendering component includes: in the rendering environment, inheriting the surface view class of the Java layer to create the native surface view class, and creating the native renderer in the C++ layer according to the rendering context handle to obtain the rendering component.
2. The texture rendering method according to claim 1, characterized in that, The rendering engine creates and passes the rendering context handle and the shared texture handle in the following ways: Obtain the image interface file and the rendering context management library, and construct the native rendering library based on the image interface file and the rendering context management library; The script file loads the native rendering library and calls the rendering event triggering method to trigger the rendering event, so as to obtain the rendering context in the rendering thread and create the rendering context handle; Create a shared texture instance and obtain the handle of the shared texture instance; The rendering context handle and the shared texture handle are passed through the native interface.
3. The texture rendering method according to claim 2, characterized in that, Obtaining the rendering context in the rendering thread includes: In response to the rendering event, the rendering event acquisition method is called to register the rendering event callback function; The rendering event callback function is executed in the rendering thread, which calls back the rendering parameter acquisition method to obtain the rendering parameters of the engine rendering environment; Based on the rendering parameters, the rendering context is obtained by calling the rendering context acquisition method provided by the rendering context management library; The native rendering library includes the rendering event acquisition method and the rendering parameter acquisition method.
4. The texture rendering method according to claim 1, characterized in that, The native renderer includes a render scheduling class, a render management class, and a render implementation class. The render scheduling class is used to call the render management class, the render management class is used to manage the render instance, and the render implementation class is used to render the shared texture.
5. The texture rendering method according to claim 1, characterized in that, The process of calling the native surface view class to instantiate the native renderer and obtain a rendering instance by monitoring the lifecycle of the target surface view includes: Based on the rendering context handle and the shared texture handle, a native surface view object is instantiated, wherein the native surface view object holds a first lifecycle method for managing the target surface view; Bind the first lifecycle method to the second lifecycle method held by the rendering scheduler class in the native renderer; Initialize the renderer identifier in the native surface view object, and call the render instance creation method in the render scheduling class based on the renderer identifier; In the rendering instance creation method, the rendering management class in the native renderer is called to create the rendering instance.
6. The texture rendering method according to claim 5, characterized in that, The step of binding the corresponding shared texture to the rendering instance based on the shared texture handle includes: By calling the texture binding method through the native surface view object, the shared texture handle and the renderer identifier are passed to the rendering scheduler class; The rendering scheduling class calls the rendering management class to locate the rendering instance based on the renderer identifier, and the rendering management class calls the texture setting method. In the texture setting method, the shared texture is bound to the rendering instance according to the shared texture handle.
7. The texture rendering method according to any one of claims 1 to 6, characterized in that, The step of rendering the shared texture onto the target surface view through the rendering instance includes: If the shared texture is one and bound to multiple target surface views, then the shared texture is rendered on each of the target surface views; If there are multiple shared textures and they are all bound to the same target surface view, then the multiple shared textures are switched and rendered on the target surface view according to a preset timing sequence. If there are multiple shared textures and multiple target surface views, then according to the preset binding relationship, the multiple shared textures are rendered on the corresponding bound target surface views.
8. A texture rendering system, characterized in that, The system includes: The acquisition module is used to acquire the rendering context handle and the shared texture handle, wherein the rendering context handle and the shared texture handle are created by the rendering engine, and the rendering context handle is created by the rendering engine calling the native rendering library, which is a native rendering library implemented in C++. A creation module is used to create a rendering environment that shares textures with the rendering engine based on the rendering context handle, and to create rendering components in the rendering environment. The rendering components include a native surface view class and a native renderer. The native surface view class is used to manage the lifecycle of the surface view, and the native renderer is used to perform texture rendering operations. The binding module is used to call the native surface view class, instantiate the native renderer by monitoring the lifecycle of the target surface view, obtain a rendering instance, and bind the corresponding shared texture to the rendering instance according to the shared texture handle; The rendering module is used to render the shared texture onto the target surface view using the rendering instance; The creation module is specifically used to obtain the rendering context of the rendering engine from the native rendering library according to the rendering context handle, and create the rendering environment according to the rendering context; in the rendering environment, the native surface view class is created by inheriting the surface view class of the Java layer, and the native renderer is created in the C++ layer according to the rendering context handle to obtain the rendering component.
9. A device terminal, characterized in that, The texture rendering method as described in any one of claims 1 to 7 may be used, or the texture rendering system as described in claim 8 may be used.
10. A computer-readable storage medium, characterized in that, It stores computer-readable instructions that, when executed by a computer's processor, cause the computer to perform a texture rendering method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Method for rendering video frame texture in real time for APP and Unity
CN115361583A