0031375: Visualization, TKOpenGl - suppress warning on WebGL 1.0
[occt.git] / samples / webgl / main.cpp
CommitLineData
565baee6 1#include <iostream>
2
3#include "WasmOcctView.h"
4
5#include <Message.hxx>
6#include <Message_Messenger.hxx>
7#include <OSD_MemInfo.hxx>
8#include <OSD_Parallel.hxx>
9
10#include <AIS_Shape.hxx>
11#include <BRepTools.hxx>
12#include <BRep_Builder.hxx>
13#include <Standard_ArrayStreamBuffer.hxx>
14
15#include <emscripten.h>
16#include <emscripten/html5.h>
17
18//! Global viewer instance.
19static WasmOcctView aViewer;
20
21//! File data read event.
22extern "C" void onFileDataRead (void* theOpaque, void* theBuffer, int theDataLen)
23{
24 const char* aName = theOpaque != NULL ? (const char* )theOpaque : "";
25 {
26 AIS_ListOfInteractive aShapes;
27 aViewer.Context()->DisplayedObjects (AIS_KOI_Shape, -1, aShapes);
28 for (AIS_ListOfInteractive::Iterator aShapeIter (aShapes); aShapeIter.More(); aShapeIter.Next())
29 {
30 aViewer.Context()->Remove (aShapeIter.Value(), false);
31 }
32 }
33
34 Standard_ArrayStreamBuffer aStreamBuffer ((const char* )theBuffer, theDataLen);
35 std::istream aStream (&aStreamBuffer);
36 TopoDS_Shape aShape;
37 BRep_Builder aBuilder;
38 BRepTools::Read (aShape, aStream, aBuilder);
39
40 Handle(AIS_Shape) aShapePrs = new AIS_Shape (aShape);
41 aShapePrs->SetMaterial (Graphic3d_NOM_SILVER);
42 aViewer.Context()->Display (aShapePrs, AIS_Shaded, 0, false);
43 aViewer.View()->FitAll (0.01, false);
44 aViewer.View()->Redraw();
45 Message::DefaultMessenger()->Send (TCollection_AsciiString("Loaded file ") + aName, Message_Info);
46 Message::DefaultMessenger()->Send (OSD_MemInfo::PrintInfo(), Message_Trace);
47}
48
49//! File read error event.
50static void onFileReadFailed (void* theOpaque)
51{
52 const char* aName = (const char* )theOpaque;
53 Message::DefaultMessenger()->Send (TCollection_AsciiString("Error: unable to load file ") + aName, Message_Fail);
54}
55
56int main()
57{
58 Message::DefaultMessenger()->Printers().First()->SetTraceLevel (Message_Trace);
59 Message::DefaultMessenger()->Send (TCollection_AsciiString("NbLogicalProcessors: ") + OSD_Parallel::NbLogicalProcessors(), Message_Trace);
60 aViewer.run();
61 Message::DefaultMessenger()->Send (OSD_MemInfo::PrintInfo(), Message_Trace);
62
63 // load some file
64 emscripten_async_wget_data ("samples/Ball.brep", (void* )"samples/Ball.brep", onFileDataRead, onFileReadFailed);
65 return 0;
66}