mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-05-10 17:40:24 +08:00
Handled __EMSCRIPTEN__ macros to:
- Workaround atomics (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 is undefined, but GCC atomics are provided).
- Suppress non-standard header <sys/signal.h> warning.
- Return OSD_LinuxREDHAT.
- Avoid inclusion of XLib headers.
- Skip fontconfig library.
- Enable EGL+GLES path (translated by Emscripten into WebGL).
- Skip eglCreatePbufferSurface() not implemented by Emscripten EGL.
Fixed Graphic3d_Vec4.hxx usage within Quantity_ColorRGBA.hxx.
OpenGl_ShaderManager::defaultGlslVersion() now prefers GLSL 300 es when WebGL 2.0 is available,
as there no any OpenGL ES greater than 3.0 emulation so far.
Shaders_Declarations.glsl - added workaround for GLSL compilation on WebGL 1.0
by defining Light properties accessors as macros instead of functions
('[]' : Index expression must be constant).
OpenGl_FrameBuffer::Init() - added workaround for initialization of GL_DEPTH24_STENCIL8
depth-stencil attachment on WebGL 1.0 + GL_WEBGL_depth_texture extension.
OpenGl_Context::Vec4FromQuantityColor() now considers myIsSRgbActive flag
to handle use case, when Immediate Layer is drawn directly into window buffer,
which is not sRGB-ready.
Added new sample - OCCT WebGL viewer.
67 lines
2.2 KiB
C++
67 lines
2.2 KiB
C++
#include <iostream>
|
|
|
|
#include "WasmOcctView.h"
|
|
|
|
#include <Message.hxx>
|
|
#include <Message_Messenger.hxx>
|
|
#include <OSD_MemInfo.hxx>
|
|
#include <OSD_Parallel.hxx>
|
|
|
|
#include <AIS_Shape.hxx>
|
|
#include <BRepTools.hxx>
|
|
#include <BRep_Builder.hxx>
|
|
#include <Standard_ArrayStreamBuffer.hxx>
|
|
|
|
#include <emscripten.h>
|
|
#include <emscripten/html5.h>
|
|
|
|
//! Global viewer instance.
|
|
static WasmOcctView aViewer;
|
|
|
|
//! File data read event.
|
|
extern "C" void onFileDataRead (void* theOpaque, void* theBuffer, int theDataLen)
|
|
{
|
|
const char* aName = theOpaque != NULL ? (const char* )theOpaque : "";
|
|
{
|
|
AIS_ListOfInteractive aShapes;
|
|
aViewer.Context()->DisplayedObjects (AIS_KOI_Shape, -1, aShapes);
|
|
for (AIS_ListOfInteractive::Iterator aShapeIter (aShapes); aShapeIter.More(); aShapeIter.Next())
|
|
{
|
|
aViewer.Context()->Remove (aShapeIter.Value(), false);
|
|
}
|
|
}
|
|
|
|
Standard_ArrayStreamBuffer aStreamBuffer ((const char* )theBuffer, theDataLen);
|
|
std::istream aStream (&aStreamBuffer);
|
|
TopoDS_Shape aShape;
|
|
BRep_Builder aBuilder;
|
|
BRepTools::Read (aShape, aStream, aBuilder);
|
|
|
|
Handle(AIS_Shape) aShapePrs = new AIS_Shape (aShape);
|
|
aShapePrs->SetMaterial (Graphic3d_NOM_SILVER);
|
|
aViewer.Context()->Display (aShapePrs, AIS_Shaded, 0, false);
|
|
aViewer.View()->FitAll (0.01, false);
|
|
aViewer.View()->Redraw();
|
|
Message::DefaultMessenger()->Send (TCollection_AsciiString("Loaded file ") + aName, Message_Info);
|
|
Message::DefaultMessenger()->Send (OSD_MemInfo::PrintInfo(), Message_Trace);
|
|
}
|
|
|
|
//! File read error event.
|
|
static void onFileReadFailed (void* theOpaque)
|
|
{
|
|
const char* aName = (const char* )theOpaque;
|
|
Message::DefaultMessenger()->Send (TCollection_AsciiString("Error: unable to load file ") + aName, Message_Fail);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
Message::DefaultMessenger()->Printers().First()->SetTraceLevel (Message_Trace);
|
|
Message::DefaultMessenger()->Send (TCollection_AsciiString("NbLogicalProcessors: ") + OSD_Parallel::NbLogicalProcessors(), Message_Trace);
|
|
aViewer.run();
|
|
Message::DefaultMessenger()->Send (OSD_MemInfo::PrintInfo(), Message_Trace);
|
|
|
|
// load some file
|
|
emscripten_async_wget_data ("samples/Ball.brep", (void* )"samples/Ball.brep", onFileDataRead, onFileReadFailed);
|
|
return 0;
|
|
}
|