-
Notifications
You must be signed in to change notification settings - Fork 11
rtrp-surface #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rtrp-surface #60
Conversation
| object SurfaceIntegrationExample: | ||
|
|
||
| def main(args: Array[String]): Unit = | ||
| println("=== Cyfra Surface Integration Example ===") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try using the logger instead of printlns - import io.computenode.cyfra.utility.Logger.logger and then you can do logger.debug(...), logger.info(...), logger.warn(..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better because it is configurable on the side of the library user - they can write a configuration of where they want the logs to go and how they want them to be formatted. Usually in production apps you will use loggers instead of println.
| activeSurfaces | ||
| .get(windowId) | ||
| .foreach: surface => | ||
| surface.resize(width, height) match | ||
| case Success(_) => | ||
| // Surface resized successfully, capabilities might have changed | ||
| surface | ||
| .getCapabilities() | ||
| .foreach: newCapabilities => | ||
| // Fire capabilities changed event (we'd need to compare with old capabilities) | ||
| fireEvent( | ||
| SurfaceEvent.SurfaceCapabilitiesChanged( | ||
| windowId, | ||
| surface.id, | ||
| newCapabilities, | ||
| newCapabilities, // TODO: track old capabilities | ||
| ), | ||
| ) | ||
|
|
||
| case Failure(ex) => | ||
| println(s"Warning: Failed to resize surface for window $windowId: ${ex.getMessage}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be rewritten as a for loop - There are two levels of nested foreach. You will need to use some methods of Try to handle the error.
| activeSurfaces | ||
| .get(windowId) | ||
| .foreach: surface => | ||
| surface.resize(width, height) match | ||
| case Success(_) => | ||
| // Surface resized successfully, capabilities might have changed | ||
| surface | ||
| .getCapabilities() | ||
| .foreach: newCapabilities => | ||
| // Fire capabilities changed event (we'd need to compare with old capabilities) | ||
| fireEvent( | ||
| SurfaceEvent.SurfaceCapabilitiesChanged( | ||
| windowId, | ||
| surface.id, | ||
| newCapabilities, | ||
| newCapabilities, // TODO: track old capabilities | ||
| ), | ||
| ) | ||
|
|
||
| case Failure(ex) => | ||
| println(s"Warning: Failed to resize surface for window $windowId: ${ex.getMessage}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be logger.error
|
|
||
| case WindowEvent.CloseRequested(windowId) => | ||
| destroySurface(windowId).recover { case ex => | ||
| println(s"Warning: Failed to destroy surface for closing window $windowId: ${ex.getMessage}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all those fails should be logger.error
Key Abstractions and Component Relationships
Core Abstractions
RenderSurface: The primary abstraction representing a surface that can be rendered toSurfaceCapabilities: Defines what a surface can doSurfaceConfig: Configuration parameters for surface creationSurfaceEvents: Surface-specific eventsVulkan Implementations
VulkanSurface: Vulkan implementation of RenderSurfaceVulkanSurfaceCapabilities: Queries and maps Vulkan-specific capabilitiesVulkanSurfaceFactory: Creates Vulkan surfaces from window handlesCentral Coordination
SurfaceManageris the central coordinator that:Public API and Main Entry Points
Creating and Managing Surfaces
Handling Surface Events
Integration with WindowManager
The
WindowManagerprovides convenient methods for creating windows with surfaces:Complete Integration Example
The
SurfaceIntegrationExampledemonstrates a complete integration workflow, including:Integration of the Surface module in our application
1. Setup and Initialization with Vulkan Context
GLFW.glfwInit())VulkanContext.withSurfaceSupport())WindowManager.withVulkanManager(vulkanContext) { manager => ... }or Manual creation and cleanup like:2. Window-Surface Creation Patterns
for example:
3. Event Handling Integration
manager.onWindowResize { event => ... })manager.onSurfaceCreated { event => ... })4. Surface Lifecycle Management
5. Error Recovery Strategies
manager.onSurfaceLost { event => println(s"Surface ${event.surfaceId} lost: ${event.error}") // Implement recovery strategy recoverFromSurfaceLoss(event.windowId, event.surfaceId) }saveApplicationState())manager.shutdown())Thread.sleep(1000))restoreApplicationState())Event Propagation
Window System Integration