revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / arch / all-hosted / libs / hostgl / hostgl_funcs.c
blobb5f372117cef4d5076610611300dcef109e39d8f
1 /*
2 Copyright 2011-2017, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define __OOP_NOATTRBASES__
8 #include <proto/exec.h>
9 #include <proto/utility.h>
10 #include <proto/graphics.h>
11 #include <proto/oop.h>
13 #include <hidd/gfx.h>
15 #include "hostgl_ctx_manager.h"
16 #include "hostgl_funcs.h"
17 #include "hostgl_support.h"
19 #include <x11gfx_bitmapclass.h>
21 #define SETFBATTR(attribute, value) \
22 { \
23 fbattributes[i++] = attribute; \
24 fbattributes[i++] = value; \
27 BOOL HostGL_FillFBAttributes(LONG * fbattributes, LONG size, struct TagItem *tagList)
29 LONG i = 0;
30 BOOL noDepth, noStencil, noAccum;
31 noStencil = GetTagData(GLA_NoStencil, GL_FALSE, tagList);
32 noAccum = GetTagData(GLA_NoAccum, GL_FALSE, tagList);
33 noDepth = GetTagData(GLA_NoDepth, GL_FALSE, tagList);
35 #if defined(RENDERER_SEPARATE_X_WINDOW)
36 SETFBATTR(GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT)
37 SETFBATTR(GLX_DOUBLEBUFFER, True);
38 #endif
40 #if defined(RENDERER_PBUFFER_WPA)
41 SETFBATTR(GLX_DRAWABLE_TYPE, GLX_PBUFFER_BIT)
42 SETFBATTR(GLX_DOUBLEBUFFER, False);
43 #endif
45 #if defined(RENDERER_PIXMAP_BLIT)
46 SETFBATTR(GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT)
47 SETFBATTR(GLX_DOUBLEBUFFER, False);
48 #endif
50 SETFBATTR(GLX_RENDER_TYPE, GLX_RGBA_BIT)
51 SETFBATTR(GLX_RED_SIZE, 1)
52 SETFBATTR(GLX_GREEN_SIZE, 1)
53 SETFBATTR(GLX_BLUE_SIZE, 1)
54 SETFBATTR(GLX_ALPHA_SIZE, 0)
56 if (noDepth)
57 SETFBATTR(GLX_DEPTH_SIZE, 0)
58 else
59 SETFBATTR(GLX_DEPTH_SIZE, 24)
61 if (noStencil)
62 SETFBATTR(GLX_STENCIL_SIZE, 0)
63 else
64 SETFBATTR(GLX_STENCIL_SIZE, 8)
66 if (noAccum)
68 SETFBATTR(GLX_ACCUM_RED_SIZE, 0)
69 SETFBATTR(GLX_ACCUM_GREEN_SIZE, 0)
70 SETFBATTR(GLX_ACCUM_BLUE_SIZE, 0)
71 SETFBATTR(GLX_ACCUM_ALPHA_SIZE, 0)
73 else
75 SETFBATTR(GLX_ACCUM_RED_SIZE, 16)
76 SETFBATTR(GLX_ACCUM_GREEN_SIZE, 16)
77 SETFBATTR(GLX_ACCUM_BLUE_SIZE, 16)
78 SETFBATTR(GLX_ACCUM_ALPHA_SIZE, 16)
81 SETFBATTR(None, None)
83 return TRUE;
86 #if defined(RENDERER_PBUFFER_WPA)
87 /* This function assumes all storages are NULL and/or have been freed */
88 VOID HostGL_AllocatePBuffer(struct hostgl_context *ctx)
90 Display * dsp = HostGL_GetGlobalX11Display();
91 LONG pbufferattributes[] =
93 GLX_PBUFFER_WIDTH, 0,
94 GLX_PBUFFER_HEIGHT, 0,
95 GLX_LARGEST_PBUFFER, False,
96 None
99 pbufferattributes[1] = ctx->framebuffer->width;
100 pbufferattributes[3] = ctx->framebuffer->height;
101 ctx->glXPbuffer = GLXCALL(glXCreatePbuffer, dsp, ctx->framebuffer->fbconfigs[0], pbufferattributes);
103 ctx->swapbuffer = AllocVec(ctx->framebuffer->width * ctx->framebuffer->height * SWAPBUFFER_BPP, MEMF_ANY);
104 ctx->swapbufferline = AllocVec(ctx->framebuffer->width * SWAPBUFFER_BPP, MEMF_ANY);
107 VOID HostGL_DeAllocatePBuffer(struct hostgl_context *ctx)
109 Display * dsp = HostGL_GetGlobalX11Display();
111 if (ctx->glXPbuffer) GLXCALL(glXDestroyPbuffer, dsp, ctx->glXPbuffer);
112 if (ctx->swapbufferline) FreeVec(ctx->swapbufferline);
113 if (ctx->swapbuffer) FreeVec(ctx->swapbuffer);
115 ctx->glXPbuffer = None;
116 ctx->swapbufferline = NULL;
117 ctx->swapbuffer = NULL;
120 static VOID HostGL_ResizePBuffer(struct hostgl_context *ctx) /* Must be called with lock held */
122 struct hostgl_context *cur_ctx = HostGL_GetCurrentContext();
123 BOOL isCurrent = (cur_ctx == ctx);
124 Display * dsp = HostGL_GetGlobalX11Display();
126 /* If current, detach */
127 if (isCurrent)
128 GLXCALL(glXMakeContextCurrent, dsp, None, None, NULL);
130 /* Destroy and recreate (using new size) */
131 HostGL_DeAllocatePBuffer(ctx);
132 HostGL_AllocatePBuffer(ctx);
134 /* If current, attach */
135 if (isCurrent)
136 GLXCALL(glXMakeContextCurrent, dsp, cur_ctx->glXPbuffer, cur_ctx->glXPbuffer, cur_ctx->glXctx);
138 ctx->framebuffer->resized = FALSE;
140 #endif
142 #if defined(RENDERER_PIXMAP_BLIT)
143 /* This function assumes all storages are NULL and/or have been freed */
144 VOID HostGL_AllocatePixmap(struct hostgl_context *ctx)
146 Display *dsp = HostGL_GetGlobalX11Display();
147 OOP_Object *hiddbm;
148 Pixmap pixmap = (Pixmap)0;
150 ctx->glXPixmapBM = AllocBitMap(ctx->framebuffer->width, ctx->framebuffer->height, 0, BMF_MINPLANES, ctx->visible_rp->BitMap);
152 #define HiddX11BitMapAB ctx->HiddX11BitMapAB
154 if(ctx->glXPixmapBM)
156 if ((hiddbm = HIDD_BM_OBJ(ctx->glXPixmapBM)))
158 OOP_GetAttr(hiddbm, aHidd_BitMap_X11_Drawable, (IPTR *) &pixmap);
160 ctx->glXPixmap = GLXCALL(glXCreateGLXPixmap, dsp, ctx->visinfo, pixmap);
163 #undef HiddX11BitMapAB
166 VOID HostGL_DeAllocatePixmap(struct hostgl_context *ctx)
168 Display * dsp = HostGL_GetGlobalX11Display();
170 if (ctx->glXPixmap) GLXCALL(glXDestroyGLXPixmap, dsp, ctx->glXPixmap);
171 if (ctx->glXPixmapBM) FreeBitMap(ctx->glXPixmapBM);
173 ctx->glXPixmap = None;
174 ctx->glXPixmapBM = NULL;
177 static VOID HostGL_ResizePixmap(struct hostgl_context * ctx) /* Must be called with lock held */
179 struct hostgl_context *cur_ctx = HostGL_GetCurrentContext();
180 BOOL isCurrent = (cur_ctx == ctx);
181 Display * dsp = HostGL_GetGlobalX11Display();
183 /* If current, detach */
184 if (isCurrent)
185 GLXCALL(glXMakeContextCurrent, dsp, None, None, NULL);
187 /* Destroy and recreate (using new size) */
188 HostGL_DeAllocatePixmap(ctx);
189 HostGL_AllocatePixmap(ctx);
191 /* If current, attach */
192 if (isCurrent)
193 GLXCALL(glXMakeContextCurrent, dsp, cur_ctx->glXPixmap, cur_ctx->glXPixmap, cur_ctx->glXctx);
195 ctx->framebuffer->resized = FALSE;
197 #endif
199 VOID HostGL_CheckAndUpdateBufferSize(struct hostgl_context * ctx)
201 HostGLRecalculateBufferWidthHeight(ctx);
202 #if defined(RENDERER_PBUFFER_WPA)
203 if (ctx->framebuffer->resized)
205 HostGL_Lock();
206 HostGL_UpdateGlobalGLXContext();
207 HostGL_ResizePBuffer(ctx);
208 HostGL_UnLock();
210 #endif
211 #if defined(RENDERER_PIXMAP_BLIT)
212 if (ctx->framebuffer->resized)
214 HostGL_Lock();
215 HostGL_UpdateGlobalGLXContext();
216 HostGL_ResizePixmap(ctx);
217 HostGL_UnLock();
219 #endif