Fixed shm resource issue
This commit is contained in:
2
Makefile
2
Makefile
@@ -4,7 +4,7 @@ obj = $(src:.c=.o)
|
||||
# Build type parameter
|
||||
|
||||
ifeq ($(BUILD),debug)
|
||||
CFLAGS_BUILD = -ggdb
|
||||
CFLAGS_BUILD = -ggdb -Wall
|
||||
GLAD_GEN = c-debug
|
||||
else
|
||||
CFLAGS_BUILD = -O2 -march=native
|
||||
|
||||
6
render.c
6
render.c
@@ -986,7 +986,7 @@ struct renderer* rd_new(const char** paths, const char* entry, const char* force
|
||||
dir = opendir(shaders);
|
||||
while ((d = readdir(dir)) != NULL) {
|
||||
if (d->d_type == DT_REG || d->d_type == DT_UNKNOWN) {
|
||||
snprintf(buf, sizeof(buf), "%d." SHADER_EXT_FRAG, idx);
|
||||
snprintf(buf, sizeof(buf), "%d." SHADER_EXT_FRAG, (int) idx);
|
||||
if (!strcmp(buf, d->d_name)) {
|
||||
printf("found GLSL stage: '%s'\n", d->d_name);
|
||||
++count;
|
||||
@@ -1007,7 +1007,7 @@ struct renderer* rd_new(const char** paths, const char* entry, const char* force
|
||||
dir = opendir(shaders);
|
||||
while ((d = readdir(dir)) != NULL) {
|
||||
if (d->d_type == DT_REG || d->d_type == DT_UNKNOWN) {
|
||||
snprintf(buf, sizeof(buf), "%d." SHADER_EXT_FRAG, idx);
|
||||
snprintf(buf, sizeof(buf), "%d." SHADER_EXT_FRAG, (int) idx);
|
||||
if (!strcmp(buf, d->d_name)) {
|
||||
printf("compiling: '%s'\n", d->d_name);
|
||||
|
||||
@@ -1218,7 +1218,7 @@ void rd_update(struct renderer* r, float* lb, float* rb, size_t bsz, bool modifi
|
||||
" fragment = texture(tex, vec2(gl_FragCoord.x / screen.x, " "\n"
|
||||
" (screen.y - gl_FragCoord.y) / screen.y));" "\n"
|
||||
" fragment.a = 1.0F;" "\n"
|
||||
"}"; "\n";
|
||||
"}" "\n";
|
||||
if (!setup) {
|
||||
bg_prog = shaderlink(shaderload(NULL, GL_VERTEX_SHADER, VERTEX_SHADER_SRC,
|
||||
NULL, NULL, 330, true),
|
||||
|
||||
18
xwin.c
18
xwin.c
@@ -6,6 +6,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
@@ -34,7 +35,7 @@ bool xwin_should_render(void) {
|
||||
unsigned long nitems, bytes_after;
|
||||
unsigned char* data;
|
||||
|
||||
int handler(Display* d, XErrorEvent* e) {}
|
||||
int handler(Display* d, XErrorEvent* e) { return 0; }
|
||||
|
||||
XSetErrorHandler(handler); /* dummy error handler */
|
||||
|
||||
@@ -130,7 +131,10 @@ unsigned int xwin_copyglbg(struct renderer* rd, unsigned int tex) {
|
||||
XVisualInfo* info = XGetVisualInfo(d, VisualIDMask, &match, &nret);
|
||||
XImage* image = XShmCreateImage(d, visual, info->depth, ZPixmap, NULL,
|
||||
&shminfo, (unsigned int) w, (unsigned int) h);
|
||||
shminfo.shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT | 0777);
|
||||
if ((shminfo.shmid = shmget(IPC_PRIVATE, image->bytes_per_line * image->height, IPC_CREAT | 0777)) == -1) {
|
||||
fprintf(stderr, "shmget() failed: %s\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
shminfo.shmaddr = image->data = shmat(shminfo.shmid, 0, 0);
|
||||
shminfo.readOnly = false;
|
||||
XShmAttach(d, &shminfo);
|
||||
@@ -200,18 +204,22 @@ unsigned int xwin_copyglbg(struct renderer* rd, unsigned int tex) {
|
||||
} else {
|
||||
/* Use image data directly. The alpha value is garbage/unassigned data, but
|
||||
we need to read it because X11 keeps pixel data aligned */
|
||||
buf = image->data;
|
||||
buf = (uint8_t*) image->data;
|
||||
/* Data could be 2, 4, or 8 byte aligned, the RGBA format and type (depth)
|
||||
already ensures reads will be properly aligned across scanlines */
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
GLenum format = image->bitmap_bit_order == LSBFirst ?
|
||||
(!aligned ? GL_BGRA : GL_BGR) :
|
||||
(!aligned ? GL_RGBA : GL_RGB);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, format, GL_UNSIGNED_BYTE, buf);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, format, type, buf);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); /* restore default */
|
||||
}
|
||||
|
||||
XFree(image);
|
||||
XShmDetach(d, &shminfo);
|
||||
shmdt(shminfo.shmaddr);
|
||||
shmctl(shminfo.shmid, IPC_RMID, NULL);
|
||||
|
||||
XDestroyImage(image);
|
||||
XCloseDisplay(d);
|
||||
|
||||
return texture;
|
||||
|
||||
Reference in New Issue
Block a user