Skip to content

feat: 添加视频纹理支持及相关功能#104

Open
BAKAOLC wants to merge 20 commits intoLegacy-LuaSTG-Engine:masterfrom
BAKAOLC:feat/video-texture
Open

feat: 添加视频纹理支持及相关功能#104
BAKAOLC wants to merge 20 commits intoLegacy-LuaSTG-Engine:masterfrom
BAKAOLC:feat/video-texture

Conversation

@BAKAOLC
Copy link

@BAKAOLC BAKAOLC commented Feb 20, 2026

This pull request introduces comprehensive support for video textures in the engine, including their loading, management, and control from both C++ and Lua APIs. It adds new resource management functions for video, exposes detailed video control and information retrieval functions to Lua, and provides example scripts for both classic and modern APIs. Additionally, it adds a configuration option to control hardware video decoding.

Video Texture Support and Resource Management

  • Added new video resource management functions: LoadVideo to ResourcePool, allowing video textures to be loaded and managed similarly to images, with support for custom options. [1] [2]
  • Integrated video texture support into the build system and includes, adding Video.hpp and Video.cpp to the engine sources and relevant includes throughout the resource and binding code. [1] [2] [3] [4]

Lua API Enhancements for Video

  • Exposed video loading and control functions to Lua: lstg.LoadVideo, lstg.VideoSeek, lstg.VideoSetLooping, lstg.VideoSetLoopRange, lstg.VideoUpdate, lstg.VideoGetInfo, lstg.VideoGetVideoStreams, lstg.VideoGetAudioStreams, and lstg.VideoReopen. These allow for fine-grained playback and information control from scripts. [1] [2] [3]
  • Added parsing of video options from Lua tables, allowing users to specify stream selection, output size, alpha premultiplication, looping, and loop ranges.

Modern API and Object-Oriented Bindings

  • Introduced a new Video class binding for the modern object-oriented Lua API, with methods for creation, property access, and registration. [1] [2]
  • Provided a modern API example (video_example_modern.lua) demonstrating object-oriented video playback and rendering.

Debug and UI Improvements

  • Updated the resource debug UI to recognize video textures, display their type, and show whether a texture is dynamic.

Configuration

  • Added a new configuration option disable_hardware_video_decode to the graphics system, controllable via config file or command-line, to allow disabling hardware video decoding if needed. [1] [2]

Examples

  • Added two example scripts: video_example.lua for classic API usage and video_example_modern.lua for the modern object-oriented API, demonstrating video loading, playback, and control. [1] [2]This pull request introduces video texture support to the engine, enabling videos to be loaded and controlled as textures in the resource system. The changes span the engine’s graphics layer, Lua bindings, and resource management, providing both API and implementation for video playback and control. The most important changes are grouped below.

Video Texture and Decoder Implementation

  • Added VideoTexture and VideoDecoder classes to support loading, decoding, and rendering video files as textures. This includes new interfaces (IVideoDecoder) and their Direct3D 11 implementations, as well as integration with the graphics device and resource management systems. ([1], [2], [3], [4])
  • Extended the graphics device interface (IGraphicsDevice) and its D3D11 implementation to create video textures and decoders, and linked Media Foundation libraries for video support. ([1], [2], [3])

Resource Manager and Lua Binding Enhancements

  • Added LoadVideo method to the resource manager, allowing videos to be loaded into the texture pool and accessed like regular textures. ([1], [2])
  • Introduced Lua bindings for video loading and control, including functions for seeking, looping, updating, and querying video info. These are exposed to Lua scripts for flexible playback control. ([1], [2], [3], [4])

Example and Documentation

  • Added a Lua example (video_example.lua) demonstrating video playback, manual update with a stopwatch, and available control functions. This serves as documentation for the new video API. (data/example/video_example.luaR1-R26)

These changes collectively enable video playback as textures, with full control and integration into the engine’s resource and scripting systems.

@BAKAOLC BAKAOLC force-pushed the feat/video-texture branch 2 times, most recently from 490a040 to c076115 Compare February 21, 2026 16:44
@BAKAOLC
Copy link
Author

BAKAOLC commented Feb 21, 2026

285d3be9745df0ac4e6093d8d568829a Hardware acceleration is now supported

@BAKAOLC BAKAOLC marked this pull request as ready for review February 22, 2026 21:44
Copilot AI review requested due to automatic review settings February 22, 2026 21:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds comprehensive video texture support to the engine, enabling videos to be loaded and rendered as textures. The implementation integrates video decoding through Microsoft Media Foundation (Direct3D 11 platform) with the existing graphics and resource management systems.

Changes:

  • Implemented VideoDecoder and VideoTexture classes with hardware-accelerated decoding support via Media Foundation
  • Extended IGraphicsDevice and ITexture2D interfaces to support video textures
  • Added LoadVideo method to resource manager for loading videos into the texture pool
  • Created Lua bindings (both modern OOP-style lstg.Video class and classic lstg.LoadVideo function)
  • Added configuration option to disable hardware video decoding
  • Provided example scripts demonstrating video playback with manual time-based updates

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
engine/graphics/d3d11/VideoDecoder.cpp Core video decoder implementation using Media Foundation with hardware acceleration support
engine/graphics/d3d11/VideoDecoder.hpp Video decoder interface with playback control and stream enumeration
engine/graphics/d3d11/VideoTexture.cpp VideoTexture wrapper combining ITexture2D and IVideoDecoder interfaces
engine/graphics/d3d11/VideoTexture.hpp VideoTexture class definition
engine/graphics/core/VideoDecoder.hpp IVideoDecoder interface with VideoOpenOptions configuration
engine/graphics/core/Texture2D.hpp Added isVideoTexture() and getVideoDecoder() to ITexture2D interface
engine/graphics/core/GraphicsDevice.hpp Added createVideoTexture() and createVideoDecoder() methods
engine/graphics/d3d11/Texture2D.hpp Implemented new interface methods for standard textures
engine/graphics/d3d11/GraphicsDevice.hpp Added video creation method declarations
engine/graphics/CMakeLists.txt Linked Media Foundation libraries
engine/configuration/core/Configuration.hpp Added disable_hardware_video_decode configuration option
engine/configuration/core/Configuration.cpp Configuration loading for hardware decode option
LuaSTG/LuaSTG/LuaBinding/modern/Video.cpp Modern OOP-style Lua binding for video control
LuaSTG/LuaSTG/LuaBinding/modern/Video.hpp Video class interface
LuaSTG/LuaSTG/LuaBinding/LuaWrapper.cpp Registered Video class
LuaSTG/LuaSTG/LuaBinding/LW_ResourceMgr.cpp Classic Lua bindings for video loading and control functions
LuaSTG/LuaSTG/GameResource/ResourcePool.cpp Implemented LoadVideo method in ResourcePool
LuaSTG/LuaSTG/GameResource/ResourceManager.h Added LoadVideo declaration
LuaSTG/LuaSTG/GameResource/ResourceDebug.cpp Updated debug view to display video texture information
data/example/video_example.lua Example demonstrating classic API usage
data/example/video_example_modern.lua Example demonstrating modern OOP API usage
LuaSTG/CMakeLists.txt Added Video.cpp/hpp to build

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add Video.hpp and Video.cpp Lua binding classes for video resource management
- Implement video information methods (getWidth, getHeight, getDuration, getCurrentTime, getFPS)
- Implement playback control methods (seek, update, setLooping, setLoopRange, getLoopRange)
- Add stream enumeration methods (getVideoStreams, getAudioStreams, getSubtitleStreams)
- Add stream selection methods (selectVideoStream, selectAudioStream, selectSubtitleStream)
- Implement getTexture method to retrieve associated Texture2D object
- Register Video class in LuaWrapper for Lua API exposure
- Add video_example_modern.lua example demonstrating video loading and playback
- Update CMakeLists.txt to include new Video binding source files
- Extend Texture2D and VideoTexture interfaces to support video decoder access
- Add null pointer checks for video decoder in Lua resource manager seek, updateToTime, and getLastOpenOptions methods
- Extract VideoOpenOptions parsing logic into reusable parseVideoOptions helper function
- Replace duplicated video options parsing code in reopen and createFromFile methods with helper function call
- Define constants for maximum stream enumeration (kMaxStreams) and post-seek decode frames (kMaxDecodeFramesAfterSeek)
- Replace magic number 16 with kMaxStreams constant for stream enumeration loops
- Replace magic number 360 with kMaxDecodeFramesAfterSeek constant for frame decode limit
- Improves code maintainability by reducing duplication and centralizing configuration constants
…e handling

- Introduce new configuration option for allowing hardware video decoding
- Refactor logic to handle enabling/disabling hardware video decode based on configuration
- Update VideoDecoder to utilize new frame rate settings, defaulting to 30 fps
- Adjust VideoTexture initialization to improve memory management with SmartReference
- Remove all Chinese language comments from VideoDecoder interface and implementation
- Replace inline HRESULT error checking with win32::check_hresult_as_boolean utility function
- Simplify error logging by removing hex error codes where utility function handles reporting
- Add string_view_literals using declaration for error message handling
- Improve code consistency and maintainability by standardizing error handling patterns
- Add blank line between VideoStreamInfo and AudioStreamInfo struct definitions for clarity
- Extract video options parsing logic into VideoBindingHelpers module for reusability
- Add MediaFoundationHelpers header for Media Foundation utilities
- Separate VideoDecoderImpl and VideoDecoderConfig into dedicated files for better organization
- Refactor video control functions to use centralized getDecoderFromResourceName helper
- Simplify error handling in VideoSeek, VideoSetLooping, VideoSetLoopRange, VideoUpdate, and VideoGetInfo functions
- Remove duplicate decoder lookup logic across multiple Lua binding functions
- Update CMakeLists.txt to include new helper source files
- Consolidate video texture and decoder retrieval into reusable helper functions
…iant

- Remove custom MediaFoundationHelpers.hpp with PropVariantGuard RAII wrapper
- Replace all PropVariantGuard instances with wil::unique_prop_variant from WIL library
- Update variable access patterns from pointer-based (var.get(), var->member) to direct member access (var.member)
- Add wil/resource.h include to VideoDecoder.cpp and VideoDecoderImpl.cpp
- Simplify PROPVARIANT management by leveraging WIL's built-in resource handling
- Reduces code duplication and improves maintainability by using standard library utilities
- Replace raw Lua C API calls with lua::stack_t wrapper for type-safe stack operations
- Simplify VideoBindingHelpers by removing custom getOptionalField and using stack.get_map_value
- Update LoadVideo, VideoSeek, VideoSetLooping, VideoUpdate, and VideoReopen functions to use stack API
- Replace lua_gettop/lua_istable with ctx.index_of_top/ctx.is_table for cleaner stack checks
- Replace lua_pushboolean with ctx.push_value for consistent value pushing
- Refactor parseVideoOptions to use lua::stack_t for table field extraction
- Update pushVideoStreamsToLua to use stack.create_array and stack.set_map_value helpers
- Change include from "lua.hpp" to "lua/plus.hpp" for access to stack wrapper utilities
- Improves code maintainability and reduces boilerplate in video resource management
- Remove unnecessary explicit casts in video binding helpers for array/map values
- Simplify stack_index_t usage by removing redundant static_cast operations
- Add constexpr constructors to stack_index_t for automatic size_t and uint32_t conversion
- Mark unused return values with [[maybe_unused]] in Video binding registration
- Add const qualifier to Video::class_name static member
- Remove unused pragma comment directives for media foundation libraries in VideoDecoder
- Remove unused include of VideoTexture.hpp from ResourceDebug.cpp
- Improves code clarity and reduces boilerplate type conversions
…cludes

- Remove unused `VideoTexture.hpp` include from ResourcePool.cpp
- Eliminate unnecessary intermediate variables in method table creation
- Eliminate unnecessary intermediate variables in metatable creation
- Remove `[[maybe_unused]]` pragmas that are no longer needed
- Simplify stack index retrieval by directly using create_module and create_metatable return values
- Add IsVideoTexture() virtual method to IResourceTexture interface
- Implement IsVideoTexture() in ResourceTextureImpl to check underlying texture
- Implement IsVideoTexture() in RenderTargetStackResourceTextureImpl returning false
- Add IsVideoTexture Lua binding to ResourceManager for texture queries
- Enable runtime detection of video textures from Lua scripts
- Add video texture detection function `IsVideoTexture` to ResourceManager
- Add comprehensive video loading and playback API documentation including `LoadVideo`, `VideoSeek`, `VideoSetLooping`, `VideoSetLoopRange`, `VideoUpdate`, `VideoGetInfo`, `VideoGetVideoStreams`, `VideoGetAudioStreams`, and `VideoReopen`
- Create new Video.lua type definition file with complete Video class API including static methods, properties, and instance methods
- Export all video-related functions to main lstg module for public API access
- Remove outdated video example files (video_example.lua and video_example_modern.lua)
- Include bilingual documentation (English and Chinese) with usage examples and parameter descriptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants