1 /*
2
3 Create an NULL OpenGL context that doesn't actually use any OpenGL code,
4 and can be compiled on a system without OpenGL.
5
6 */
7
8 #include <vector>
9
10 #include "OffscreenContext.h"
11 #include "printutils.h"
12 #include "imageutils.h"
13
14 #include <map>
15 #include <string>
16 #include <sstream>
17
18 using namespace std;
19
20 struct OffscreenContext
21 {
22 int width;
23 int height;
24 };
25
offscreen_context_init(OffscreenContext & ctx,int width,int height)26 void offscreen_context_init(OffscreenContext &ctx, int width, int height)
27 {
28 ctx.width = width;
29 ctx.height = height;
30 }
31
offscreen_context_getinfo(OffscreenContext * ctx)32 string offscreen_context_getinfo(OffscreenContext *ctx)
33 {
34 const char *arch = "unknown";
35 if (sizeof(int*) == 4) arch = "32-bit";
36 else if (sizeof(int*) == 8) arch = "64-bit";
37 #ifdef OPENSCAD_OS
38 auto OSInfo = OPENSCAD_OS;
39 #else
40 auto OSInfo = "unknown";
41 #endif
42 return STR("OS info: " << OSInfo
43 << "\nMachine: " << arch << "\n");
44 }
45
create_offscreen_context(int w,int h)46 OffscreenContext *create_offscreen_context(int w, int h)
47 {
48 OffscreenContext *ctx = new OffscreenContext;
49 offscreen_context_init( *ctx, w, h );
50 return ctx;
51 }
52
teardown_offscreen_context(OffscreenContext * ctx)53 bool teardown_offscreen_context(OffscreenContext *ctx)
54 {
55 return true;
56 }
57
save_framebuffer(const OffscreenContext * ctx,char const * filename)58 bool save_framebuffer(const OffscreenContext *ctx, char const * filename)
59 {
60 std::ofstream fstream(filename,std::ios::out|std::ios::binary);
61 if (!fstream.is_open()) {
62 std::cerr << "Can't open file " << filename << " for writing";
63 return false;
64 } else {
65 save_framebuffer(ctx, fstream);
66 fstream.close();
67 }
68 return true;
69 }
70
save_framebuffer(const OffscreenContext * ctx,std::ostream & output)71 bool save_framebuffer(const OffscreenContext *ctx, std::ostream &output)
72 {
73 output << "NULLGL framebuffer";
74 return true;
75 }
76
77