Skip to content

Commit

Permalink
EngineGLCreateInfo: added WebGL context initialization attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Sep 30, 2023
1 parent d2595cb commit f5e0fbb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
38 changes: 38 additions & 0 deletions Graphics/GraphicsEngine/interface/GraphicsTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -3424,6 +3424,39 @@ struct EngineCreateInfo
};
typedef struct EngineCreateInfo EngineCreateInfo;

#if PLATFORM_EMSCRIPTEN
/// WebGL context attributes.
///
/// \remarks This struct is used to set the members of the EmscriptenWebGLContextAttributes
/// structure that is passed to emscripten_webgl_create_context().
struct WebGLContextAttribs
{
/// If true, request alpha channel for the context and enable blending of
/// the canvas with the underlying web page contents.
///
/// \remarks This corresponds to the alpha member of the EmscriptenWebGLContextAttributes struct.
Bool Alpha DEFAULT_INITIALIZER(true);

/// If true, enable antialiasing with a browser-specified algorithm and quality level.
///
/// \remarks This corresponds to the antialias member of the EmscriptenWebGLContextAttributes struct.
Bool Antialias DEFAULT_INITIALIZER(true);

/// If true, treat the rendered canvas contents as alpha-premultiplied.
///
/// \remarks This corresponds to the premultipliedAlpha member of the EmscriptenWebGLContextAttributes struct.
Bool PremultipliedAlpha DEFAULT_INITIALIZER(true);

/// If true, preserve the contents of the drawing buffer between consecutive requestAnimationFrame() calls.
/// If false, clear the color, depth and stencil at the beginning of each requestAnimationFrame().
/// Generally setting this to false gives better performance.
///
/// \remarks This corresponds to the preserveDrawingBuffer member of the EmscriptenWebGLContextAttributes struct.
Bool PreserveDrawingBuffer DEFAULT_INITIALIZER(false);
};
typedef struct WebGLContextAttribs WebGLContextAttribs;
#endif

/// Attributes of the OpenGL-based engine implementation
struct EngineGLCreateInfo DILIGENT_DERIVE(EngineCreateInfo)

Expand All @@ -3434,6 +3467,11 @@ struct EngineGLCreateInfo DILIGENT_DERIVE(EngineCreateInfo)
/// Use IRenderDevice::GetDeviceInfo().NDC to get current NDC.
Bool ZeroToOneNDZ DEFAULT_INITIALIZER(false);

#if PLATFORM_EMSCRIPTEN
/// WebGL context attributes.
WebGLContextAttribs WebGLAttribs;
#endif

#if DILIGENT_CPP_INTERFACE
EngineGLCreateInfo() noexcept : EngineGLCreateInfo{EngineCreateInfo{}}
{}
Expand Down
11 changes: 7 additions & 4 deletions Graphics/GraphicsEngineOpenGL/src/GLContextEmscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ GLContext::GLContext(const EngineGLCreateInfo& InitAttribs, RENDER_DEVICE_TYPE&
EmscriptenWebGLContextAttributes ContextAttributes = {};
emscripten_webgl_init_context_attributes(&ContextAttributes);

// TODO: Initialization params
ContextAttributes.depth = true;
ContextAttributes.majorVersion = 3;
ContextAttributes.minorVersion = 0;
ContextAttributes.depth = true;
ContextAttributes.majorVersion = 3;
ContextAttributes.minorVersion = 0;
ContextAttributes.alpha = InitAttribs.WebGLAttribs.Alpha;
ContextAttributes.antialias = InitAttribs.WebGLAttribs.Antialias;
ContextAttributes.premultipliedAlpha = InitAttribs.WebGLAttribs.PremultipliedAlpha;
ContextAttributes.preserveDrawingBuffer = InitAttribs.WebGLAttribs.PreserveDrawingBuffer;

m_GLContext = emscripten_webgl_create_context(InitAttribs.Window.pCanvasId, &ContextAttributes);
if (m_GLContext == 0)
Expand Down

0 comments on commit f5e0fbb

Please sign in to comment.