Skip to content

Comments

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

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

feat: 添加视频纹理支持及相关功能#104
BAKAOLC wants to merge 11 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
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.

2 participants