Commit Graph

34 Commits (master)

Author SHA1 Message Date
jpark37 b4cc32c4c9 libobs: Extend NVIDIA anti-flicker to desktops 2022-08-29 10:02:32 -07:00
jpark37 37389ff243 libobs: Avoid display clear workaround if possible 2022-08-27 16:32:50 -07:00
jpark37 f88300a613 libobs: Emulate clear with draw for displays
Laptops that render OBS displays on NVIDIA, and display through Intel
have been seen flickering, and we think the driver is not properly
handling swap chain buffers that have been cleared but not drawn to. To
work around this, we use a draw to simulate a render target clear. This
is not as efficient, so hopefully NVIDIA will fix this soon.
2022-08-24 05:01:08 -07:00
jpark37 fb146fa370 libobs: Remove display GPU markers without draws 2022-08-09 20:21:27 -07:00
Norihiro Kamae c42047cb68 libobs: Fix missing pair of GS_DEBUG_MARKER
The conditional branch added by 4fe6803fe resulted GS_DEBUG_MARKER_END
is not called when the branch condition is failed.
2022-08-06 17:24:56 -07:00
jpark37 4fe6803fe4 libobs: Prevent D3D11 projectors from tearing
Some users stream projectors, so don't let them tear. Use the waitable
object to check the flip queue, and only flip if there's space.

Metal and Vulkan can probably perform similar flip throttling once OBS
starts using them.
2022-08-06 16:16:20 -07:00
jpark37 01c0486aad libobs: Add obs_display_update_color_space 2022-03-23 22:35:26 -07:00
jpark37 5d1261eddb libobs: Only resize display if dimensions change 2022-02-26 01:09:07 -08:00
jp9000 f53df7da64 clang-format: Apply formatting
Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed.  Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.
2019-06-23 23:49:10 -07:00
James Park 5471e74cbe libobs: UI: Remove Qt usage from graphics thread
This fixes Xcode warning about detecting UI usage from another thread.
2019-05-09 23:30:37 -07:00
James Park 21f4dd63d4 libobs: UI: Use graphics debug markers
Add D3D/GL debug markers to make RenderDoc captures easier to tranverse.

Also add obs_source_get_name_no_null() to avoid boilerplate for safe
string formatting.

Closes obsproject/obs-studio#1799
2019-04-08 02:05:37 -07:00
jp9000 03cca9d95a libobs: Background color of 0 should not be gray
When calling obs_display_set_background_color, the value set in the
'color' parameter should always be used as-is.  0 should not indicate a
color other than black.  To do anything otherwise is silly and confusing
for users of the API.

Closes obsproject/obs-studio#1516
2018-12-03 04:09:30 -08:00
cg2121 0ae8a7c0ac UI: Add ability to style preview background color 2018-09-10 04:55:15 -05:00
Richard Stanway 8b640fae24
Fix various null pointer issues detected by Coverity 2017-02-25 16:45:45 +01:00
jp9000 e541e170a3 libobs: Fix possible reverse order mutex hard lock
For displays, instead of using the draw_callbacks_mutex and risk a
reverse mutual lock scenario, use a separate mutex to lock display size
data.

This bug was exposed when trying to reorder filters in the UI module.
The UI thread would try to reorder the filters, locking the filter mutex
of the source, and then the reorder would signal the UI to resize the
display, so the display would lock its draw_callbacks_mutex.  Then, in
the graphics thread, it would lock the display's draw_callbacks_mutex,
try to draw the source, and then the source would try to lock that same
filter mutex.

A mutex trace:
UI thread -> lock source filter mutex -> waiting on display mutex
graphics thread -> lock display mutex -> waiting on source filter mutex

Closes jp9000/obs-studio#714
2016-12-17 15:21:00 -08:00
jp9000 27a0749d8d libobs: Add func to set display background color
This function sets the background color for a display
2015-04-10 07:27:23 -07:00
jp9000 ebfe477caf libobs: Add ability to disable displays
Sometimes it can be useful to turn off rendering to the display in order
to reduce the number of draw calls and present calls.
2015-04-10 07:27:21 -07:00
jp9000 41fad2d1a4 (API Change) Use const params where applicable
This Fixes a minor flaw with the API where data had to always be mutable
to be usable by the API.

Functions that do not modify the fundamental underlying data of a
structure should be marked as constant, both for safety and to signify
that the parameter is input only and will not be modified by the
function using it.
2014-09-26 17:23:07 -07:00
GoaLitiuM 10f5d7f3aa Fixed NULL pointer dereferencing in linked lists 2014-09-27 01:35:36 +03:00
jp9000 c9df41c1e2 (API Change) Remove pointers from all typedefs
Typedef pointers are unsafe.  If you do:
typedef struct bla *bla_t;
then you cannot use it as a constant, such as: const bla_t, because
that constant will be to the pointer itself rather than to the
underlying data.  I admit this was a fundamental mistake that must
be corrected.

All typedefs that were pointer types will now have their pointers
removed from the type itself, and the pointers will be used when they
are actually used as variables/parameters/returns instead.

This does not break ABI though, which is pretty nice.
2014-09-25 21:48:11 -07:00
jp9000 5780f3f177 (API Change) Improve graphics API consistency
Summary:
- Prefix all graphics subsystem names with gs_ or GS_
- Unsquish funciton names (for example _setfloat to _set_float)
- Changed create functions to be more consistent with the rest of the
  API elsewhere.  For exmaple, instead of
  gs_create_texture/gs_texture_destroy, it's now
  gs_texture_create/gs_texture_destroy
- Renamed gs_stencil_op enum to gs_stencil_op_type

From:                            To:
-----------------------------------------------------------
tvertarray                       gs_tvertarray
vb_data                          gs_vb_data
vbdata_create                    gs_vbdata_create
vbdata_destroy                   gs_vbdata_destroy
shader_param                     gs_shader_param
gs_effect                        gs_effect
effect_technique                 gs_effect_technique
effect_pass                      gs_effect_pass
effect_param                     gs_effect_param
texture_t                        gs_texture_t
stagesurf_t                      gs_stagesurf_t
zstencil_t                       gs_zstencil_t
vertbuffer_t                     gs_vertbuffer_t
indexbuffer_t                    gs_indexbuffer_t
samplerstate_t                   gs_samplerstate_t
swapchain_t                      gs_swapchain_t
texrender_t                      gs_texrender_t
shader_t                         gs_shader_t
sparam_t                         gs_sparam_t
effect_t                         gs_effect_t
technique_t                      gs_technique_t
eparam_t                         gs_eparam_t
device_t                         gs_device_t
graphics_t                       graphics_t
shader_param_type                gs_shader_param_type
SHADER_PARAM_UNKNOWN             GS_SHADER_PARAM_UNKNOWN
SHADER_PARAM_BOOL                GS_SHADER_PARAM_BOOL
SHADER_PARAM_FLOAT               GS_SHADER_PARAM_FLOAT
SHADER_PARAM_INT                 GS_SHADER_PARAM_INT
SHADER_PARAM_STRING              GS_SHADER_PARAM_STRING
SHADER_PARAM_VEC2                GS_SHADER_PARAM_VEC2
SHADER_PARAM_VEC3                GS_SHADER_PARAM_VEC3
SHADER_PARAM_VEC4                GS_SHADER_PARAM_VEC4
SHADER_PARAM_MATRIX4X4           GS_SHADER_PARAM_MATRIX4X4
SHADER_PARAM_TEXTURE             GS_SHADER_PARAM_TEXTURE
shader_param_info                gs_shader_param_info
shader_type                      gs_shader_type
SHADER_VERTEX                    GS_SHADER_VERTEX
SHADER_PIXEL                     GS_SHADER_PIXEL
shader_destroy                   gs_shader_destroy
shader_numparams                 gs_shader_get_num_params
shader_getparambyidx             gs_shader_get_param_by_idx
shader_getparambyname            gs_shader_get_param_by_name
shader_getviewprojmatrix         gs_shader_get_viewproj_matrix
shader_getworldmatrix            gs_shader_get_world_matrix
shader_getparaminfo              gs_shader_get_param_info
shader_setbool                   gs_shader_set_bool
shader_setfloat                  gs_shader_set_float
shader_setint                    gs_shader_set_int
shader_setmatrix3                gs_shader_setmatrix3
shader_setmatrix4                gs_shader_set_matrix4
shader_setvec2                   gs_shader_set_vec2
shader_setvec3                   gs_shader_set_vec3
shader_setvec4                   gs_shader_set_vec4
shader_settexture                gs_shader_set_texture
shader_setval                    gs_shader_set_val
shader_setdefault                gs_shader_set_default
effect_property_type             gs_effect_property_type
EFFECT_NONE                      GS_EFFECT_NONE
EFFECT_BOOL                      GS_EFFECT_BOOL
EFFECT_FLOAT                     GS_EFFECT_FLOAT
EFFECT_COLOR                     GS_EFFECT_COLOR
EFFECT_TEXTURE                   GS_EFFECT_TEXTURE
effect_param_info                gs_effect_param_info
effect_destroy                   gs_effect_destroy
effect_gettechnique              gs_effect_get_technique
technique_begin                  gs_technique_begin
technique_end                    gs_technique_end
technique_beginpass              gs_technique_begin_pass
technique_beginpassbyname        gs_technique_begin_pass_by_name
technique_endpass                gs_technique_end_pass
effect_numparams                 gs_effect_get_num_params
effect_getparambyidx             gs_effect_get_param_by_idx
effect_getparambyname            gs_effect_get_param_by_name
effect_updateparams              gs_effect_update_params
effect_getviewprojmatrix         gs_effect_get_viewproj_matrix
effect_getworldmatrix            gs_effect_get_world_matrix
effect_getparaminfo              gs_effect_get_param_info
effect_setbool                   gs_effect_set_bool
effect_setfloat                  gs_effect_set_float
effect_setint                    gs_effect_set_int
effect_setmatrix4                gs_effect_set_matrix4
effect_setvec2                   gs_effect_set_vec2
effect_setvec3                   gs_effect_set_vec3
effect_setvec4                   gs_effect_set_vec4
effect_settexture                gs_effect_set_texture
effect_setval                    gs_effect_set_val
effect_setdefault                gs_effect_set_default
texrender_create                 gs_texrender_create
texrender_destroy                gs_texrender_destroy
texrender_begin                  gs_texrender_begin
texrender_end                    gs_texrender_end
texrender_reset                  gs_texrender_reset
texrender_gettexture             gs_texrender_get_texture
GS_BUILDMIPMAPS                  GS_BUILD_MIPMAPS
GS_RENDERTARGET                  GS_RENDER_TARGET
gs_device_name                   gs_get_device_name
gs_device_type                   gs_get_device_type
gs_entercontext                  gs_enter_context
gs_leavecontext                  gs_leave_context
gs_getcontext                    gs_get_context
gs_renderstart                   gs_render_start
gs_renderstop                    gs_render_stop
gs_rendersave                    gs_render_save
gs_getinput                      gs_get_input
gs_geteffect                     gs_get_effect
gs_create_effect_from_file       gs_effect_create_from_file
gs_create_effect                 gs_effect_create
gs_create_vertexshader_from_file gs_vertexshader_create_from_file
gs_create_pixelshader_from_file  gs_pixelshader_create_from_file
gs_create_texture_from_file      gs_texture_create_from_file
gs_resetviewport                 gs_reset_viewport
gs_set2dmode                     gs_set_2d_mode
gs_set3dmode                     gs_set_3d_mode
gs_create_swapchain              gs_swapchain_create
gs_getsize                       gs_get_size
gs_getwidth                      gs_get_width
gs_getheight                     gs_get_height
gs_create_texture                gs_texture_create
gs_create_cubetexture            gs_cubetexture_create
gs_create_volumetexture          gs_voltexture_create
gs_create_zstencil               gs_zstencil_create
gs_create_stagesurface           gs_stagesurface_create
gs_create_samplerstate           gs_samplerstate_create
gs_create_vertexshader           gs_vertexshader_create
gs_create_pixelshader            gs_pixelshader_create
gs_create_vertexbuffer           gs_vertexbuffer_create
gs_create_indexbuffer            gs_indexbuffer_create
gs_gettexturetype                gs_get_texture_type
gs_load_defaultsamplerstate      gs_load_default_samplerstate
gs_getvertexshader               gs_get_vertex_shader
gs_getpixelshader                gs_get_pixel_shader
gs_getrendertarget               gs_get_render_target
gs_getzstenciltarget             gs_get_zstencil_target
gs_setrendertarget               gs_set_render_target
gs_setcuberendertarget           gs_set_cube_render_target
gs_beginscene                    gs_begin_scene
gs_draw                          gs_draw
gs_endscene                      gs_end_scene
gs_setcullmode                   gs_set_cull_mode
gs_getcullmode                   gs_get_cull_mode
gs_enable_depthtest              gs_enable_depth_test
gs_enable_stenciltest            gs_enable_stencil_test
gs_enable_stencilwrite           gs_enable_stencil_write
gs_blendfunction                 gs_blend_function
gs_depthfunction                 gs_depth_function
gs_stencilfunction               gs_stencil_function
gs_stencilop                     gs_stencil_op
gs_setviewport                   gs_set_viewport
gs_getviewport                   gs_get_viewport
gs_setscissorrect                gs_set_scissor_rect
gs_create_texture_from_iosurface gs_texture_create_from_iosurface
gs_create_gdi_texture            gs_texture_create_gdi
gs_is_compressed_format          gs_is_compressed_format
gs_num_total_levels              gs_get_total_levels
texture_setimage                 gs_texture_set_image
cubetexture_setimage             gs_cubetexture_set_image
swapchain_destroy                gs_swapchain_destroy
texture_destroy                  gs_texture_destroy
texture_getwidth                 gs_texture_get_width
texture_getheight                gs_texture_get_height
texture_getcolorformat           gs_texture_get_color_format
texture_map                      gs_texture_map
texture_unmap                    gs_texture_unmap
texture_isrect                   gs_texture_is_rect
texture_getobj                   gs_texture_get_obj
cubetexture_destroy              gs_cubetexture_destroy
cubetexture_getsize              gs_cubetexture_get_size
cubetexture_getcolorformat       gs_cubetexture_get_color_format
volumetexture_destroy            gs_voltexture_destroy
volumetexture_getwidth           gs_voltexture_get_width
volumetexture_getheight          gs_voltexture_get_height
volumetexture_getdepth           gs_voltexture_getdepth
volumetexture_getcolorformat     gs_voltexture_get_color_format
stagesurface_destroy             gs_stagesurface_destroy
stagesurface_getwidth            gs_stagesurface_get_width
stagesurface_getheight           gs_stagesurface_get_height
stagesurface_getcolorformat      gs_stagesurface_get_color_format
stagesurface_map                 gs_stagesurface_map
stagesurface_unmap               gs_stagesurface_unmap
zstencil_destroy                 gs_zstencil_destroy
samplerstate_destroy             gs_samplerstate_destroy
vertexbuffer_destroy             gs_vertexbuffer_destroy
vertexbuffer_flush               gs_vertexbuffer_flush
vertexbuffer_getdata             gs_vertexbuffer_get_data
indexbuffer_destroy              gs_indexbuffer_destroy
indexbuffer_flush                gs_indexbuffer_flush
indexbuffer_getdata              gs_indexbuffer_get_data
indexbuffer_numindices           gs_indexbuffer_get_num_indices
indexbuffer_gettype              gs_indexbuffer_get_type
texture_rebind_iosurface         gs_texture_rebind_iosurface
texture_get_dc                   gs_texture_get_dc
texture_release_dc               gs_texture_release_dc
2014-08-09 11:57:38 -07:00
jp9000 41176eef27 (API Change) Remove obs_graphics()
API Removed:
- graphics_t obs_graphics();
Replaced With:
- void obs_enter_graphics();
- void obs_leave_graphics();

Description:
  obs_graphics() was somewhat of a pointless function.  The only time
that it was ever necessary was to pass it as a parameter to
gs_entercontext() followed by a subsequent gs_leavecontext() call after
that.  So, I felt that it made a bit more sense just to implement
obs_enter_graphics() and obs_leave_graphics() functions to do the exact
same thing without having to repeat that code.  There's really no need
to ever "hold" the graphics pointer, though I suppose that could change
in the future so having a similar function come back isn't out of the
question.

Still, this at least reduces the amount of unnecessary repeated code for
the time being.
2014-08-08 11:04:45 -07:00
jp9000 4a6d19f206 libobs: Add services API, reduce repeated code
Add API for streaming services.  The services API simplifies the
creation of custom service features and user interface.

Custom streaming services later on will be able to do things such as:

 - Be able to use service-specific APIs via modules, allowing a more
   direct means of communicating with the service and requesting or
   setting service-specific information

 - Get URL/stream key via other means of authentication such as OAuth,
   or be able to build custom URLs for services that require that sort
   of thing.

 - Query information (such as viewer count, chat, follower
   notifications, and other information)

 - Set channel information (such as current game, current channel title,
   activating commercials)

Also, I reduce some repeated code that was used for all libobs objects.
This includes the name of the object, the private data, settings, as
well as the signal and procedure handlers.

I also switched to using linked lists for the global object lists,
rather than using an array of pointers (you could say it was..
pointless.)  ..Anyway, the linked list info is also stored in the shared
context data structure.
2014-04-19 20:38:53 -07:00
jp9000 d9251f9e87 Add source properties window (very preliminary)
- Add a properties window for sources so that you can now actually edit
   the settings for sources.  Also, display the source by itself in the
   window (Note: not working on mac, and possibly not working on linux).

   When changing the settings for a source, it will call
   obs_source_update on that source when you have modified any values
   automatically.

 - Add a properties 'widget', eventually I want to turn this in to a
   regular nice properties view like you'd see in the designer, but
   right now it just uses a form layout in a QScrollArea with regular
   controls to display the properties.  It's clunky but works for the
   time being.

 - Make it so that swap chains and the main graphics subsystem will
   automatically use at least one backbuffer if none was specified

 - Fix bug where displays weren't added to the main display array

 - Make it so that you can get the properties of a source via the actual
   pointer of a source/encoder/output in addition to being able to look
   up properties via identifier.

 - When registering source types, check for required functions (wasn't
   doing it before).  getheight/getwidth should not be optional if it's
   a video source as well.

 - Add an RAII OBSObj wrapper to obs.hpp for non-reference-counted
   libobs pointers

 - Add an RAII OBSSignal wrapper to obs.hpp for libobs signals to
   automatically disconnect them on destruction

 - Move the "scale and center" calculation in window-basic-main.cpp to
   its own function and in its own source file

 - Add an 'update' callback to WASAPI audio sources
2014-03-23 01:07:54 -07:00
jp9000 e8044d0868 Use only one widget for preview
Modify the obs_display API so that it always uses an orthographic
projection that is the size of the display, rather than OBS' base size.
Having it do an orthographic projection to OBS' base size was silly
because it meant that everything would be skewed if you wanted to draw
1:1 in the display.  This deoes mean that the callbacks must handle
resizing the images, but it's worth it to ensure 1:1 draw sizes.

As for the preview widget, instead of making some funky widget within
widget that resizes, it's just going to be a widget within the entire
top layout.  Also changed the preview padding color to gray.
2014-03-07 10:19:03 -07:00
jp9000 966b943d5b Remove majority of warnings
There were a *lot* of warnings, managed to remove most of them.

Also, put warning flags before C_FLAGS and CXX_FLAGS, rather than after,
as -Wall -Wextra was overwriting flags that came before it.
2014-02-14 15:13:36 -07:00
jp9000 515f44be8e Revamp rendering system to allow custom rendering
Originally, the rendering system was designed to only display sources
and such, but I realized there would be a flaw; if you wanted to render
the main viewport in a custom way, or maybe even the entire application
as a graphics-based front end, you wouldn't have been able to do that.

Displays have now been separated in to viewports and displays.  A
viewport is used to store and draw sources, a display is used to handle
draw callbacks.  You can even use displays without using viewports to
draw custom render displays containing graphics calls if you wish, but
usually they would be used in combination with source viewports at
least.

This requires a tiny bit more work to create simple source displays, but
in the end its worth it for the added flexibility and options it brings.
2014-02-13 08:58:31 -07:00
jp9000 b067440f73 Use bzalloc instead of bmalloc then memset
Reduces needless code repetition and still allows for proper memory
alignment.  Cleans up the code a bit.
2014-02-09 12:34:07 -07:00
jp9000 103ef75310 Improve thread safety for scene items
Scene items previously were removed by calling obs_sceneitem_destroy,
but this proved to be a potential race condition where two different
threads could try to destroy the same scene item at the same time.

Instead of doing that, reference counting is now used on scene items,
and an explicit obs_sceneitem_remove function is used instead for item
removal, which sets a 'removed' variable to ensure it can only be called
exactly one time.
2014-01-30 01:31:52 -07:00
jp9000 563613db8f Rename obs-data.h to obs-internal.h
Renaming obs-data.h to avoid confusion about its usage
2014-01-26 18:48:14 -07:00
jp9000 8298fa4dc7 With the permission of my fellow contributors, I'm switching obs-studio back to GPL v2+ to prevent issues between this project and the original OBS project, and for personal reasons to avoid legal ambiguity (not political reasons, I admittedly would prefer GPL v3+) 2013-12-02 22:24:38 -07:00
jp9000 409b011a8e cleaned up main internal data structure design, changed to reference counting for sources to ensure safe destruction of source objects from all parts of the system, added some service-related stuff for testing 2013-11-20 15:00:16 -07:00
jp9000 9570f0b8d7 change names, fix some bugs, minor GL/D3D fixes, update tests, fix effect files, output a little more debug information 2013-10-14 12:37:52 -07:00
jp9000 f255ae1922 first commit 2013-09-30 19:37:13 -07:00