Mesa: Makefiles
git-svn-id: svn://kolibrios.org@4768 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
a116ccf850
commit
88ffef6c2e
@ -12,6 +12,8 @@ LDFLAGS = -nostdlib -shared -s --image-base 0 -T ../newlib/dll.lds --out-implib
|
||||
|
||||
STRIP = $(PREFIX)strip
|
||||
|
||||
export SDK_DIR:= $(abspath ../..)
|
||||
|
||||
INC_MESA= -I../newlib/include -I./include -I./src -I./src/glsl -I./src/mesa -I./src/mapi
|
||||
INC_EGL= -I../newlib/include -I../../includes -I./include -I../libdrm -I../libdrm/include/drm -I./src/egl/main -I./src/gbm/backends/dri -I./src/gbm/main
|
||||
|
||||
@ -26,142 +28,16 @@ MESA_DEFS+= -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDI
|
||||
|
||||
EGL_DEFS = -DHAVE_DRM_PLATFORM -D__unix__ -DMESA_EGL_NO_X11_HEADERS -D_EGL_BUILT_IN_DRIVER_DRI2
|
||||
|
||||
EGL_SRC = \
|
||||
src/egl/drivers/dri2/egl_dri2.c \
|
||||
src/egl/drivers/dri2/platform_drm.c \
|
||||
src/egl/main/eglapi.c \
|
||||
src/egl/main/eglarray.c \
|
||||
src/egl/main/eglconfig.c \
|
||||
src/egl/main/eglcontext.c \
|
||||
src/egl/main/eglcurrent.c \
|
||||
src/egl/main/egldisplay.c \
|
||||
src/egl/main/egldriver.c \
|
||||
src/egl/main/eglfallbacks.c \
|
||||
src/egl/main/eglglobals.c \
|
||||
src/egl/main/eglimage.c \
|
||||
src/egl/main/egllog.c \
|
||||
src/egl/main/eglmisc.c \
|
||||
src/egl/main/eglmode.c \
|
||||
src/egl/main/eglscreen.c \
|
||||
src/egl/main/eglstring.c \
|
||||
src/egl/main/eglsurface.c \
|
||||
src/egl/main/eglsync.c \
|
||||
src/gbm/backends/dri/driver_name.c \
|
||||
src/gbm/backends/dri/gbm_dri.c \
|
||||
src/gbm/main/backend.c \
|
||||
src/gbm/main/gbm.c \
|
||||
$(NULL)
|
||||
|
||||
GLSL_SRC = \
|
||||
src/glsl/glcpp/glcpp-lex.c \
|
||||
src/glsl/glcpp/glcpp-parse.c \
|
||||
src/glsl/glcpp/pp.c \
|
||||
src/glsl/ast_array_index.cpp \
|
||||
src/glsl/ast_expr.cpp \
|
||||
src/glsl/ast_function.cpp \
|
||||
src/glsl/ast_to_hir.cpp \
|
||||
src/glsl/ast_type.cpp \
|
||||
src/glsl/builtin_function.cpp \
|
||||
src/glsl/builtin_types.cpp \
|
||||
src/glsl/builtin_variables.cpp \
|
||||
src/glsl/glsl_lexer.cpp \
|
||||
src/glsl/glsl_parser.cpp \
|
||||
src/glsl/glsl_parser_extras.cpp \
|
||||
src/glsl/glsl_symbol_table.cpp \
|
||||
src/glsl/glsl_types.cpp \
|
||||
src/glsl/hir_field_selection.cpp \
|
||||
src/glsl/ir.cpp \
|
||||
src/glsl/ir_basic_block.cpp \
|
||||
src/glsl/ir_builder.cpp \
|
||||
src/glsl/ir_clone.cpp \
|
||||
src/glsl/ir_constant_expression.cpp \
|
||||
src/glsl/ir_expression_flattening.cpp \
|
||||
src/glsl/ir_function.cpp \
|
||||
src/glsl/ir_function_can_inline.cpp \
|
||||
src/glsl/ir_function_detect_recursion.cpp \
|
||||
src/glsl/ir_hierarchical_visitor.cpp \
|
||||
src/glsl/ir_hv_accept.cpp \
|
||||
src/glsl/ir_import_prototypes.cpp \
|
||||
src/glsl/ir_print_visitor.cpp \
|
||||
src/glsl/ir_reader.cpp \
|
||||
src/glsl/ir_rvalue_visitor.cpp \
|
||||
src/glsl/ir_set_program_inouts.cpp \
|
||||
src/glsl/ir_validate.cpp \
|
||||
src/glsl/ir_variable_refcount.cpp \
|
||||
src/glsl/link_functions.cpp \
|
||||
src/glsl/link_interface_blocks.cpp \
|
||||
src/glsl/link_uniform_block_active_visitor.cpp \
|
||||
src/glsl/link_uniform_blocks.cpp \
|
||||
src/glsl/link_uniform_initializers.cpp \
|
||||
src/glsl/link_uniforms.cpp \
|
||||
src/glsl/link_varyings.cpp \
|
||||
src/glsl/linker.cpp \
|
||||
src/glsl/loop_analysis.cpp \
|
||||
src/glsl/loop_controls.cpp \
|
||||
src/glsl/loop_unroll.cpp \
|
||||
src/glsl/lower_clip_distance.cpp \
|
||||
src/glsl/lower_discard.cpp \
|
||||
src/glsl/lower_discard_flow.cpp \
|
||||
src/glsl/lower_if_to_cond_assign.cpp \
|
||||
src/glsl/lower_instructions.cpp \
|
||||
src/glsl/lower_jumps.cpp \
|
||||
src/glsl/lower_mat_op_to_vec.cpp \
|
||||
src/glsl/lower_named_interface_blocks.cpp \
|
||||
src/glsl/lower_noise.cpp \
|
||||
src/glsl/lower_output_reads.cpp \
|
||||
src/glsl/lower_packed_varyings.cpp \
|
||||
src/glsl/lower_packing_builtins.cpp \
|
||||
src/glsl/lower_texture_projection.cpp \
|
||||
src/glsl/lower_ubo_reference.cpp \
|
||||
src/glsl/lower_variable_index_to_cond_assign.cpp \
|
||||
src/glsl/lower_vec_index_to_cond_assign.cpp \
|
||||
src/glsl/lower_vec_index_to_swizzle.cpp \
|
||||
src/glsl/lower_vector.cpp \
|
||||
src/glsl/lower_vector_insert.cpp \
|
||||
src/glsl/opt_algebraic.cpp \
|
||||
src/glsl/opt_array_splitting.cpp \
|
||||
src/glsl/opt_constant_folding.cpp \
|
||||
src/glsl/opt_constant_propagation.cpp \
|
||||
src/glsl/opt_constant_variable.cpp \
|
||||
src/glsl/opt_copy_propagation.cpp \
|
||||
src/glsl/opt_copy_propagation_elements.cpp \
|
||||
src/glsl/opt_dead_builtin_varyings.cpp \
|
||||
src/glsl/opt_dead_code.cpp \
|
||||
src/glsl/opt_dead_code_local.cpp \
|
||||
src/glsl/opt_dead_functions.cpp \
|
||||
src/glsl/opt_flatten_nested_if_blocks.cpp \
|
||||
src/glsl/opt_flip_matrices.cpp \
|
||||
src/glsl/opt_function_inlining.cpp \
|
||||
src/glsl/opt_if_simplification.cpp \
|
||||
src/glsl/opt_noop_swizzle.cpp \
|
||||
src/glsl/opt_redundant_jumps.cpp \
|
||||
src/glsl/opt_structure_splitting.cpp \
|
||||
src/glsl/opt_swizzle_swizzle.cpp \
|
||||
src/glsl/opt_tree_grafting.cpp \
|
||||
src/glsl/ralloc.c \
|
||||
src/glsl/s_expression.cpp \
|
||||
src/glsl/strtod.c \
|
||||
$(NULL)
|
||||
|
||||
LIBGL_SRC = \
|
||||
src/mapi/glapi/glapi.c \
|
||||
src/mapi/glapi/glapi_dispatch.c \
|
||||
src/mapi/glapi/glapi_entrypoint.c \
|
||||
src/mapi/glapi/glapi_getproc.c \
|
||||
src/mapi/glapi/glapi_nop.c \
|
||||
src/mapi/glapi/glapi_x86.S \
|
||||
src/mapi/u_current.c \
|
||||
src/mapi/u_execmem.c \
|
||||
$(NULL)
|
||||
|
||||
EGL_OBJS = $(patsubst %.c, %.o, $(EGL_SRC))
|
||||
GLSL_OBJS = $(patsubst %.cpp, %.o, $(patsubst %.c, %.o, $(GLSL_SRC)))
|
||||
LIBGL_OBJS = $(patsubst %.c, %.o, $(patsubst %.S, %.o, $(LIBGL_SRC)))
|
||||
SUBDIRS = src/egl src/glsl src/mapi src/mesa
|
||||
|
||||
# targets
|
||||
|
||||
all: libGL.dll $(EGL).dll libglsl.a
|
||||
|
||||
all:
|
||||
@echo $(SDK_DIR); \
|
||||
for i in $(SUBDIRS); do \
|
||||
$(MAKE) -C $$i; \
|
||||
done
|
||||
|
||||
$(EGL).dll: $(EGL_OBJS) Makefile
|
||||
$(LD) $(LDFLAGS) $(LIBPATH) -o $@ egl.def $(EGL_OBJS) $(LIBS)
|
||||
$(STRIP) $@
|
||||
|
@ -44,7 +44,7 @@ LIBGL_OBJS = $(patsubst %.c, %.o, $(patsubst %.S, %.o, $(LIBGL_SRC)))
|
||||
all: libGL.dll
|
||||
|
||||
libGL.dll: $(LIBGL_OBJS) Makefile
|
||||
$(LD) $(LDFLAGS) $(LIBPATH) -o $@ $(LIBGL_OBJS) $(LIBS)
|
||||
$(LD) $(LDFLAGS) $(LIBPATH) -o $@ mesa.def $(LIBGL_OBJS) $(LIBS)
|
||||
$(STRIP) $@
|
||||
mv -f $@ $(SDK_DIR)/bin
|
||||
mv -f libGL.dll.a $(SDK_DIR)/lib
|
||||
|
@ -1,21 +1,26 @@
|
||||
|
||||
LIBRARY= libeglut
|
||||
IMPLIB= libeglut.dll.a
|
||||
|
||||
|
||||
CC=gcc
|
||||
CFLAGS = -U_Win32 -U_WIN32 -U__MINGW32__ -c -O2 -fomit-frame-pointer
|
||||
|
||||
AR= ar
|
||||
|
||||
INCLUDES= -I. -I../newlib/include -I../Mesa/include -I../Mesa/src/gbm/main -I../render
|
||||
INCLUDES= -I. -I../newlib/include -I../Mesa/include -I../Mesa/src/gbm/main -I../libdrm/include
|
||||
|
||||
LDFLAGS:= -shared -s -nostdlib -T ../newlib/dll.lds --entry _DllStartup --image-base=0 --out-implib $(IMPLIB)
|
||||
LIBPATH:= -L../../lib
|
||||
|
||||
LIBS:= -ldll -legl.dll -lgl.dll -lc.dll
|
||||
|
||||
DEFINES= -D__unix__ -DMESA_EGL_NO_X11_HEADERS
|
||||
|
||||
|
||||
SOURCES = eglut.c \
|
||||
eglut_screen.c
|
||||
eglut_screen.c\
|
||||
render.c \
|
||||
swap.c
|
||||
|
||||
|
||||
OBJECTS = $(patsubst %.c, %.o, $(SOURCES))
|
||||
@ -24,13 +29,18 @@ OBJECTS = $(patsubst %.c, %.o, $(SOURCES))
|
||||
# targets
|
||||
|
||||
|
||||
all:$(LIBRARY).a
|
||||
all:$(LIBRARY).a $(LIBRARY).dll
|
||||
|
||||
$(LIBRARY).a: $(OBJECTS) Makefile
|
||||
ar cvrs $(LIBRARY).a $(OBJECTS)
|
||||
mv -f $(LIBRARY).a ../../lib
|
||||
|
||||
%.o : %.c Makefile
|
||||
$(LIBRARY).dll: $(OBJECTS) Makefile
|
||||
$(LD) $(LDFLAGS) $(LIBPATH) -o $@ $(OBJECTS) $(LIBS)
|
||||
mv -f $(LIBRARY).dll ../../bin
|
||||
mv -f $(IMPLIB) ../../lib
|
||||
|
||||
%.o : %.c Makefile eglut.h eglutint.h render.h
|
||||
$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -o $@ $<
|
||||
|
||||
clean:
|
||||
|
@ -66,12 +66,8 @@ int
|
||||
_eglutNow(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
#ifdef __VMS
|
||||
(void) gettimeofday(&tv, NULL );
|
||||
#else
|
||||
struct timezone tz;
|
||||
(void) gettimeofday(&tv, &tz);
|
||||
#endif
|
||||
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
|
@ -156,12 +156,11 @@ _eglutNativeEventLoop(void)
|
||||
int ev;
|
||||
|
||||
ev = check_os_event();
|
||||
// ev = get_os_event();
|
||||
switch(ev)
|
||||
{
|
||||
case 1:
|
||||
BeginDraw();
|
||||
DrawWindow(10,10,10,10,NULL,0,0x74);
|
||||
DrawWindow(0,0,0,0,NULL,0,0x74);
|
||||
EndDraw();
|
||||
break;
|
||||
|
||||
|
514
contrib/sdk/sources/eglut/render.c
Normal file
514
contrib/sdk/sources/eglut/render.c
Normal file
@ -0,0 +1,514 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "render.h"
|
||||
#include <drm/i915_drm.h>
|
||||
#include <kos32sys.h>
|
||||
|
||||
void create_mask(struct render *render);
|
||||
|
||||
static int drm_ioctl(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
ioctl_t io;
|
||||
|
||||
io.handle = fd;
|
||||
io.io_code = request;
|
||||
io.input = arg;
|
||||
io.inp_size = 64;
|
||||
io.output = NULL;
|
||||
io.out_size = 0;
|
||||
|
||||
return call_service(&io);
|
||||
}
|
||||
|
||||
static EGLImageKHR px_create_image(EGLDisplay display, EGLContext context,
|
||||
int width, int height, int stride, int name)
|
||||
{
|
||||
EGLImageKHR image;
|
||||
EGLint attribs[] = {
|
||||
EGL_WIDTH, 0,
|
||||
EGL_HEIGHT, 0,
|
||||
EGL_DRM_BUFFER_STRIDE_MESA, 0,
|
||||
EGL_DRM_BUFFER_FORMAT_MESA,
|
||||
EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
|
||||
EGL_DRM_BUFFER_USE_MESA,
|
||||
EGL_DRM_BUFFER_USE_SHARE_MESA |
|
||||
EGL_DRM_BUFFER_USE_SCANOUT_MESA,
|
||||
EGL_NONE
|
||||
};
|
||||
attribs[1] = width;
|
||||
attribs[3] = height;
|
||||
attribs[5] = stride/4;
|
||||
|
||||
printf("%s w:%d :%d pitch:%d handle %d\n", __FUNCTION__,
|
||||
width, height, stride, name);
|
||||
|
||||
image = eglCreateImageKHR(display, context, EGL_DRM_BUFFER_MESA,
|
||||
(void *) (uintptr_t)name, attribs);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
static GLint create_shader(GLenum type, const char *source)
|
||||
{
|
||||
GLint ok;
|
||||
GLint shader;
|
||||
|
||||
shader = glCreateShader(type);
|
||||
if(shader == 0)
|
||||
goto err;
|
||||
|
||||
glShaderSource(shader, 1, (const GLchar **) &source, NULL);
|
||||
glCompileShader(shader);
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
|
||||
if (!ok) {
|
||||
GLchar *info;
|
||||
GLint size;
|
||||
|
||||
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &size);
|
||||
info = malloc(size);
|
||||
|
||||
glGetShaderInfoLog(shader, size, NULL, info);
|
||||
printf("Failed to compile %s: %s\n",
|
||||
type == GL_FRAGMENT_SHADER ? "FS" : "VS",info);
|
||||
printf("Program source:\n%s", source);
|
||||
printf("GLSL compile failure\n");
|
||||
free(info);
|
||||
glDeleteShader(shader);
|
||||
shader = 0;
|
||||
}
|
||||
err:
|
||||
return shader;
|
||||
}
|
||||
|
||||
|
||||
struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy)
|
||||
{
|
||||
const char *vs_src =
|
||||
"attribute vec4 v_position;\n"
|
||||
"attribute vec4 v_texcoord0;\n"
|
||||
"varying vec2 source_texture;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = v_position;\n"
|
||||
" source_texture = v_texcoord0.xy;\n"
|
||||
"}\n";
|
||||
|
||||
const char *fs_i965 =
|
||||
"varying vec2 source_texture;\n"
|
||||
"uniform sampler2D sampler_src;\n"
|
||||
"uniform sampler2D sampler_mask;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" float ca = texture2D(sampler_mask, source_texture).r;\n"
|
||||
" gl_FragColor = vec4(texture2D(sampler_src, source_texture).rgb, ca);\n"
|
||||
"}\n";
|
||||
|
||||
const char *fs_i915 =
|
||||
"varying vec2 source_texture;\n"
|
||||
"uniform sampler2D sampler_src;\n"
|
||||
"uniform sampler2D sampler_mask;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" float ca = texture2D(sampler_mask, source_texture).a;\n"
|
||||
" gl_FragColor = vec4(texture2D(sampler_src, source_texture).rgb, ca);\n"
|
||||
"}\n";
|
||||
|
||||
EGLint config_attribs[14];
|
||||
EGLConfig config;
|
||||
EGLint num_configs;
|
||||
|
||||
EGLContext context;
|
||||
|
||||
struct drm_i915_fb_info fb;
|
||||
GLint vs_shader, fs_shader;
|
||||
GLenum status;
|
||||
GLint ret;
|
||||
int fd;
|
||||
struct render *render;
|
||||
char *drv_name;
|
||||
const char *fs_src;
|
||||
|
||||
|
||||
fd = get_service("DISPLAY");
|
||||
|
||||
memset(&fb, 0, sizeof(fb));
|
||||
ret = drm_ioctl(fd, SRV_FBINFO, &fb);
|
||||
if( ret != 0 )
|
||||
{ printf("failed to get framebuffer info\n");
|
||||
goto err;
|
||||
};
|
||||
|
||||
render = (struct render*)malloc(sizeof(struct render));
|
||||
if(render == NULL)
|
||||
goto err;
|
||||
|
||||
render->fd = fd;
|
||||
render->dpy = dpy;
|
||||
render->dx = dx;
|
||||
render->dy = dy;
|
||||
|
||||
if(!eglQuerySurface(dpy, surface, EGL_WIDTH, &render->width))
|
||||
goto err1;
|
||||
|
||||
if(!eglQuerySurface(dpy, surface, EGL_HEIGHT, &render->height))
|
||||
goto err1;
|
||||
|
||||
render->scr_width = fb.width;
|
||||
render->scr_height = fb.height;
|
||||
|
||||
render->front = eglGetBufferImage(dpy, surface, EGL_DRM_BUFFER_FRONT);
|
||||
if(render->front == EGL_NO_IMAGE_KHR)
|
||||
goto err1;
|
||||
|
||||
render->back = eglGetBufferImage(dpy, surface, EGL_DRM_BUFFER_BACK);
|
||||
if( render->back == EGL_NO_IMAGE_KHR)
|
||||
goto err2;
|
||||
|
||||
|
||||
context = eglGetCurrentContext();
|
||||
|
||||
config_attribs[0] = EGL_RED_SIZE;
|
||||
config_attribs[1] = 1;
|
||||
config_attribs[2] = EGL_GREEN_SIZE;
|
||||
config_attribs[3] = 1;
|
||||
config_attribs[4] = EGL_BLUE_SIZE;
|
||||
config_attribs[5] = 1;
|
||||
config_attribs[6] = EGL_DEPTH_SIZE;
|
||||
config_attribs[7] = 1;
|
||||
|
||||
config_attribs[8] = EGL_SURFACE_TYPE;
|
||||
config_attribs[9] = EGL_WINDOW_BIT;
|
||||
|
||||
config_attribs[10] = EGL_RENDERABLE_TYPE;
|
||||
config_attribs[11] = EGL_OPENGL_BIT;
|
||||
config_attribs[12] = EGL_NONE;
|
||||
|
||||
if (!eglChooseConfig(dpy,config_attribs, &config, 1, &num_configs) || !num_configs)
|
||||
{
|
||||
printf("failed to choose a config");
|
||||
goto err3;
|
||||
}
|
||||
|
||||
render->context = eglCreateContext(dpy, config, EGL_NO_CONTEXT, NULL);
|
||||
if (!context)
|
||||
{
|
||||
printf("failed to create context");
|
||||
goto err3;
|
||||
};
|
||||
|
||||
if (!eglMakeCurrent(dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context))
|
||||
{
|
||||
printf("failed to make window current");
|
||||
goto err4;
|
||||
};
|
||||
|
||||
|
||||
glGenTextures(2, render->tx_buffers);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err5;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, render->tx_buffers[EGL_DRM_BUFFER_FRONT]);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err6;
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->front);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err6;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, render->tx_buffers[EGL_DRM_BUFFER_BACK]);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err6;
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->back);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err6;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
render->back_buffer = EGL_DRM_BUFFER_FRONT;
|
||||
|
||||
render->screen = px_create_image(dpy,context,fb.width,fb.height,
|
||||
fb.pitch,fb.name);
|
||||
if(render->screen == EGL_NO_IMAGE_KHR)
|
||||
goto err6;
|
||||
|
||||
glGenTextures(1, &render->tx_screen);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err6;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, render->tx_screen);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err7;
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,render->screen);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err7;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
create_mask(render);
|
||||
|
||||
glGenFramebuffers(1, &render->framebuffer);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err8;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, render->framebuffer);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err9;
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,
|
||||
GL_TEXTURE_2D, render->tx_screen,0);
|
||||
|
||||
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
const char *str;
|
||||
switch (status)
|
||||
{
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
str = "incomplete attachment";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
|
||||
str = "incomplete/missing attachment";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
|
||||
str = "incomplete draw buffer";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
||||
str = "incomplete read buffer";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
str = "unsupported";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
|
||||
str = "incomplete multiple";
|
||||
break;
|
||||
default:
|
||||
str = "unknown error";
|
||||
break;
|
||||
}
|
||||
printf("destination is framebuffer incomplete: %s [%#x]\n", str, status);
|
||||
goto err9;
|
||||
}
|
||||
|
||||
glViewport(0, 0, render->scr_width, render->scr_height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
drv_name = (char*)glGetString(0x1F04);
|
||||
printf("Render: %s\n", drv_name);
|
||||
|
||||
if(strstr(drv_name, "i965"))
|
||||
fs_src = fs_i965;
|
||||
else if(strstr(drv_name, "i915"))
|
||||
fs_src = fs_i915;
|
||||
else fs_src = NULL;
|
||||
|
||||
render->blit_prog = glCreateProgram();
|
||||
if(render->blit_prog == 0)
|
||||
goto err9;
|
||||
|
||||
vs_shader = create_shader(GL_VERTEX_SHADER,vs_src);
|
||||
if(vs_shader == 0)
|
||||
goto err10;
|
||||
|
||||
fs_shader = create_shader(GL_FRAGMENT_SHADER, fs_src);
|
||||
if(fs_shader == 0)
|
||||
goto err11;
|
||||
|
||||
glAttachShader(render->blit_prog, vs_shader);
|
||||
glAttachShader(render->blit_prog, fs_shader);
|
||||
glBindAttribLocation(render->blit_prog, 0, "v_position");
|
||||
glBindAttribLocation(render->blit_prog, 1, "v_texcoord0");
|
||||
|
||||
glLinkProgram(render->blit_prog);
|
||||
glGetProgramiv(render->blit_prog, GL_LINK_STATUS, &ret);
|
||||
if (!ret)
|
||||
{
|
||||
GLchar *info;
|
||||
GLint size;
|
||||
|
||||
glGetProgramiv(render->blit_prog, GL_INFO_LOG_LENGTH, &size);
|
||||
info = malloc(size);
|
||||
|
||||
glGetProgramInfoLog(render->blit_prog, size, NULL, info);
|
||||
printf("Failed to link: %s\n", info);
|
||||
printf("GLSL link failure\n");
|
||||
free(info);
|
||||
goto err12;
|
||||
}
|
||||
|
||||
render->sampler = glGetUniformLocation(render->blit_prog,"sampler_src");
|
||||
render->sm_mask = glGetUniformLocation(render->blit_prog,"sampler_mask");
|
||||
|
||||
glUseProgram(render->blit_prog);
|
||||
glUniform1i(render->sampler, 0);
|
||||
glUniform1i(render->sm_mask, 1);
|
||||
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT,GL_FALSE, 2 * sizeof(float),render->vertices);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float),render->tc_src);
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
render->tc_src[0] = 0.0;
|
||||
render->tc_src[1] = 0.0;
|
||||
render->tc_src[1*2] = 1.0;
|
||||
render->tc_src[1*2+1]= 0.0;
|
||||
render->tc_src[2*2] = 1.0;
|
||||
render->tc_src[2*2+1]= 1.0;
|
||||
render->tc_src[3*2] = 0.0;
|
||||
render->tc_src[3*2+1]= 1.0;
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, render->tx_mask);
|
||||
glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MIN_FILTER,
|
||||
GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,
|
||||
GL_TEXTURE_MAG_FILTER,
|
||||
GL_NEAREST);
|
||||
|
||||
eglMakeCurrent(dpy, surface, surface, context);
|
||||
|
||||
return render;
|
||||
|
||||
err12:
|
||||
glDeleteShader(fs_shader);
|
||||
err11:
|
||||
glDeleteShader(vs_shader);
|
||||
err10:
|
||||
glDeleteProgram(render->blit_prog);
|
||||
err9:
|
||||
glDeleteFramebuffers(1, &render->framebuffer);
|
||||
err8:
|
||||
eglDestroyImageKHR(dpy, render->screen);
|
||||
err7:
|
||||
glDeleteTextures(1, &render->tx_screen);
|
||||
err6:
|
||||
glDeleteTextures(2, render->tx_buffers);
|
||||
err5:
|
||||
eglMakeCurrent(dpy, surface, surface, context);
|
||||
err4:
|
||||
eglDestroyContext(dpy, render->context);
|
||||
err3:
|
||||
eglDestroyImageKHR(dpy, render->back);
|
||||
err2:
|
||||
eglDestroyImageKHR(dpy, render->front);
|
||||
err1:
|
||||
free(render);
|
||||
err:
|
||||
return NULL;
|
||||
};
|
||||
|
||||
|
||||
void create_mask(struct render *render)
|
||||
{
|
||||
struct drm_i915_gem_create create;
|
||||
struct drm_gem_close close;
|
||||
struct drm_gem_flink flink;
|
||||
|
||||
struct drm_i915_gem_mmap mmap_arg;
|
||||
EGLint handle, stride;
|
||||
int winw, winh, pitch;
|
||||
void *data;
|
||||
int ret;
|
||||
GLuint mask_handle, mask_name;
|
||||
EGLImageKHR mask_image;
|
||||
|
||||
glGenTextures(1, &render->tx_mask);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
return;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, render->tx_mask);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err1;
|
||||
|
||||
pitch = (render->width+15) & ~15;
|
||||
|
||||
create.size = pitch *render->height;
|
||||
create.handle = 0;
|
||||
ret = drm_ioctl(render->fd, DRM_IOCTL_I915_GEM_CREATE, &create);
|
||||
if(ret != 0)
|
||||
goto err1;
|
||||
|
||||
mask_handle = create.handle;
|
||||
flink.handle = create.handle;
|
||||
ret = drm_ioctl(render->fd, DRM_IOCTL_GEM_FLINK, &flink);
|
||||
if (ret != 0)
|
||||
goto err2;
|
||||
|
||||
mask_name = flink.name;
|
||||
|
||||
printf("create mask bo handle %d name %d\n", create.handle, flink.name);
|
||||
|
||||
EGLint attribs[] = {
|
||||
EGL_WIDTH, 0,
|
||||
EGL_HEIGHT, 0,
|
||||
EGL_DRM_BUFFER_STRIDE_MESA, 0,
|
||||
EGL_DRM_BUFFER_FORMAT_MESA,
|
||||
EGL_DRM_BUFFER_FORMAT_R8_MESA,
|
||||
EGL_DRM_BUFFER_USE_MESA,
|
||||
EGL_DRM_BUFFER_USE_SHARE_MESA,
|
||||
EGL_NONE
|
||||
};
|
||||
attribs[1] = pitch;
|
||||
attribs[3] = render->height;
|
||||
attribs[5] = pitch;
|
||||
|
||||
mask_image = eglCreateImageKHR(render->dpy, render->context, EGL_DRM_BUFFER_MESA,
|
||||
(void *) (uintptr_t)mask_name, attribs);
|
||||
printf("create mask image %p\n", mask_image);
|
||||
if(mask_image == NULL)
|
||||
goto err2;
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, mask_image);
|
||||
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err3;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
mmap_arg.handle = mask_handle;
|
||||
mmap_arg.offset = 0;
|
||||
mmap_arg.size = pitch * render->height;
|
||||
if (drm_ioctl(render->fd, DRM_IOCTL_I915_GEM_MMAP, &mmap_arg))
|
||||
{
|
||||
printf("%s: failed to mmap image %p handle=%d, %d bytes, into CPU domain\n",
|
||||
__FUNCTION__, mask_image, mask_handle, pitch * render->height);
|
||||
goto err3;
|
||||
}
|
||||
|
||||
render->mask_handle = mask_handle;
|
||||
render->mask_name = mask_name;
|
||||
render->mask_buffer = (void *)(uintptr_t)mmap_arg.addr_ptr;
|
||||
render->mask_image = mask_image;
|
||||
|
||||
return;
|
||||
|
||||
err3:
|
||||
eglDestroyImageKHR(render->dpy, mask_image);
|
||||
err2:
|
||||
close.handle = mask_handle;
|
||||
(void)drm_ioctl(render->fd, DRM_IOCTL_GEM_CLOSE, &close);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
err1:
|
||||
glDeleteTextures(1, &render->tx_mask);
|
||||
};
|
46
contrib/sdk/sources/eglut/render.h
Normal file
46
contrib/sdk/sources/eglut/render.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef __GL_RENDER_H__
|
||||
#define __GL_RENDER_H__
|
||||
|
||||
#define EGL_EGLEXT_PROTOTYPES
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include "EGL/egl.h"
|
||||
#include "EGL/eglext.h"
|
||||
#include "GL/gl.h"
|
||||
|
||||
enum px_buffer
|
||||
{
|
||||
PX_FRONT = 0,
|
||||
PX_BACK = 1
|
||||
};
|
||||
|
||||
struct render
|
||||
{
|
||||
int fd;
|
||||
EGLDisplay dpy;
|
||||
EGLContext context;
|
||||
EGLint dx, dy;
|
||||
EGLint width, height;
|
||||
EGLint scr_width, scr_height;
|
||||
GLuint framebuffer;
|
||||
EGLImageKHR screen, front, back;
|
||||
GLuint tx_buffers[2];
|
||||
GLuint tx_screen;
|
||||
GLuint tx_mask;
|
||||
|
||||
GLuint mask_handle;
|
||||
GLuint mask_name;
|
||||
void *mask_buffer;
|
||||
EGLImageKHR mask_image;
|
||||
|
||||
int back_buffer;
|
||||
GLuint blit_prog;
|
||||
GLint sampler, sm_mask;
|
||||
float vertices[8],tc_src[8],tc_mask[8];
|
||||
};
|
||||
|
||||
struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy);
|
||||
void render_blit(struct render *render, enum px_buffer buffer);
|
||||
void render_swap_and_blit(struct render *render);
|
||||
|
||||
#endif /* __GL_RENDER_H__ */
|
107
contrib/sdk/sources/eglut/swap.c
Normal file
107
contrib/sdk/sources/eglut/swap.c
Normal file
@ -0,0 +1,107 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "render.h"
|
||||
#include <drm/i915_drm.h>
|
||||
#include <kos32sys.h>
|
||||
|
||||
#define WIN_STATE_MINIMIZED 0x02
|
||||
#define WIN_STATE_ROLLED 0x04
|
||||
|
||||
static int drm_ioctl(int fd, unsigned long request, void *arg)
|
||||
{
|
||||
ioctl_t io;
|
||||
|
||||
io.handle = fd;
|
||||
io.io_code = request;
|
||||
io.input = arg;
|
||||
io.inp_size = 64;
|
||||
io.output = NULL;
|
||||
io.out_size = 0;
|
||||
|
||||
return call_service(&io);
|
||||
}
|
||||
|
||||
void render_swap_and_blit(struct render *render)
|
||||
{
|
||||
char proc_info[1024];
|
||||
struct drm_i915_mask_update update;
|
||||
|
||||
EGLContext context;
|
||||
EGLSurface draw, read;
|
||||
uint32_t winx, winy, winw, winh;
|
||||
uint8_t state;
|
||||
float xscale, yscale;
|
||||
float *vertices = render->vertices;
|
||||
float *texcoords = render->tc_src;
|
||||
int r, b;
|
||||
|
||||
if(render == NULL)
|
||||
return;
|
||||
|
||||
get_proc_info(proc_info);
|
||||
|
||||
winx = *(uint32_t*)(proc_info+34);
|
||||
winy = *(uint32_t*)(proc_info+38);
|
||||
winw = *(uint32_t*)(proc_info+42)+1;
|
||||
winh = *(uint32_t*)(proc_info+46)+1;
|
||||
state = *(uint8_t*)(proc_info+70);
|
||||
|
||||
if(state & (WIN_STATE_MINIMIZED|WIN_STATE_ROLLED))
|
||||
return;
|
||||
|
||||
context = eglGetCurrentContext();
|
||||
draw = eglGetCurrentSurface(EGL_DRAW);
|
||||
read = eglGetCurrentSurface(EGL_READ);
|
||||
|
||||
eglSwapBuffers(render->dpy,draw);
|
||||
|
||||
render->back_buffer++;
|
||||
render->back_buffer&=1;
|
||||
|
||||
update.handle = render->mask_handle;
|
||||
update.dx = render->dx;
|
||||
update.dy = render->dy;
|
||||
update.width = render->width;
|
||||
update.height = render->height;
|
||||
update.bo_pitch = (render->width+15) & ~15;
|
||||
update.bo_map = (int)render->mask_buffer;
|
||||
|
||||
if(drm_ioctl(render->fd, 45, &update))
|
||||
return;
|
||||
|
||||
if (!eglMakeCurrent(render->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, render->context))
|
||||
{
|
||||
printf("failed to make window current");
|
||||
goto err1;
|
||||
};
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, render->tx_buffers[render->back_buffer]);
|
||||
|
||||
xscale = 1.0/render->scr_width;
|
||||
yscale = 1.0/render->scr_height;
|
||||
|
||||
r = winx + render->dx + render->width;
|
||||
b = winy + render->dy + render->height;
|
||||
|
||||
float t0, t1, t2, t5;
|
||||
|
||||
vertices[0] = t0 = 2*(winx+render->dx)*xscale - 1.0;
|
||||
vertices[1 * 2] = t2 = 2*r*xscale - 1.0;
|
||||
|
||||
vertices[2 * 2] = t2;
|
||||
vertices[3 * 2] = t0;
|
||||
|
||||
vertices[1] = t1 = 2*(winy+render->dy)*yscale - 1.0;
|
||||
vertices[2*2+1] = t5 = 2*b*yscale - 1.0;
|
||||
vertices[1*2+1] = t1;
|
||||
vertices[3*2+1] = t5;
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
|
||||
err1:
|
||||
eglMakeCurrent(render->dpy, draw, read, context);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
LIBRARY= gcc_eh
|
||||
LIBRARY= libgcc_eh
|
||||
|
||||
CC=gcc
|
||||
CPP=g++
|
||||
|
@ -962,15 +962,6 @@ struct drm_i915_reset_stats {
|
||||
__u32 pad;
|
||||
};
|
||||
|
||||
struct drm_i915_mask_update {
|
||||
__u32 handle;
|
||||
__u32 width;
|
||||
__u32 height;
|
||||
__u32 bo_size;
|
||||
__u32 bo_pitch;
|
||||
__u32 bo_map;
|
||||
};
|
||||
|
||||
struct drm_i915_fb_info {
|
||||
__u32 name;
|
||||
__u32 width;
|
||||
@ -981,4 +972,14 @@ struct drm_i915_fb_info {
|
||||
__u32 pipe;
|
||||
};
|
||||
|
||||
struct drm_i915_mask_update {
|
||||
__u32 handle;
|
||||
__u32 dx;
|
||||
__u32 dy;
|
||||
__u32 width;
|
||||
__u32 height;
|
||||
__u32 bo_pitch;
|
||||
__u32 bo_map;
|
||||
};
|
||||
|
||||
#endif /* _I915_DRM_H_ */
|
||||
|
@ -322,7 +322,7 @@ int user_free(void *mem)
|
||||
static inline
|
||||
int *user_unmap(void *base, size_t offset, size_t size)
|
||||
{
|
||||
void *val;
|
||||
int *val;
|
||||
__asm__ __volatile__(
|
||||
"int $0x40"
|
||||
:"=a"(val)
|
||||
|
@ -76,7 +76,7 @@ static GLint create_shader(GLenum type, const char *source)
|
||||
printf("Program source:\n%s", source);
|
||||
printf("GLSL compile failure\n");
|
||||
free(info);
|
||||
glDeleteProgram(shader);
|
||||
glDeleteShader(shader);
|
||||
shader = 0;
|
||||
}
|
||||
err:
|
||||
@ -325,6 +325,7 @@ struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy)
|
||||
printf("Failed to link: %s\n", info);
|
||||
printf("GLSL link failure\n");
|
||||
free(info);
|
||||
goto err12;
|
||||
}
|
||||
|
||||
render->sampler = glGetUniformLocation(render->blit_prog,"sampler_src");
|
||||
@ -365,6 +366,8 @@ struct render* create_render(EGLDisplay dpy, EGLSurface surface, int dx, int dy)
|
||||
|
||||
return render;
|
||||
|
||||
err12:
|
||||
glDeleteShader(fs_shader);
|
||||
err11:
|
||||
glDeleteShader(vs_shader);
|
||||
err10:
|
||||
@ -392,11 +395,10 @@ err:
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
void create_mask(struct render *render)
|
||||
{
|
||||
struct drm_i915_gem_create create;
|
||||
struct drm_gem_close close;
|
||||
struct drm_gem_flink flink;
|
||||
|
||||
struct drm_i915_gem_mmap mmap_arg;
|
||||
@ -407,7 +409,6 @@ void create_mask(struct render *render)
|
||||
GLuint mask_handle, mask_name;
|
||||
EGLImageKHR mask_image;
|
||||
|
||||
|
||||
glGenTextures(1, &render->tx_mask);
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
return;
|
||||
@ -416,7 +417,6 @@ void create_mask(struct render *render)
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err1;
|
||||
|
||||
|
||||
pitch = (render->width+15) & ~15;
|
||||
|
||||
create.size = pitch *render->height;
|
||||
@ -425,12 +425,12 @@ void create_mask(struct render *render)
|
||||
if(ret != 0)
|
||||
goto err1;
|
||||
|
||||
mask_handle = create.handle;
|
||||
flink.handle = create.handle;
|
||||
ret = drm_ioctl(render->fd, DRM_IOCTL_GEM_FLINK, &flink);
|
||||
if (ret != 0)
|
||||
goto err2;
|
||||
|
||||
mask_handle = create.handle;
|
||||
mask_name = flink.name;
|
||||
|
||||
printf("create mask bo handle %d name %d\n", create.handle, flink.name);
|
||||
@ -451,9 +451,9 @@ void create_mask(struct render *render)
|
||||
|
||||
mask_image = eglCreateImageKHR(render->dpy, render->context, EGL_DRM_BUFFER_MESA,
|
||||
(void *) (uintptr_t)mask_name, attribs);
|
||||
|
||||
printf("create mask image %p\n", mask_image);
|
||||
|
||||
if(mask_image == NULL)
|
||||
goto err2
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
|
||||
@ -461,7 +461,7 @@ void create_mask(struct render *render)
|
||||
glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, mask_image);
|
||||
|
||||
if(glGetError() != GL_NO_ERROR)
|
||||
goto err2;
|
||||
goto err3;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
@ -483,8 +483,10 @@ void create_mask(struct render *render)
|
||||
return;
|
||||
|
||||
err3:
|
||||
// eglDestroyImageKHR(render->dpy, render->mask);
|
||||
eglDestroyImageKHR(render->dpy, mask_image);
|
||||
err2:
|
||||
close.handle = mask_handle;
|
||||
(void)drm_ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
err1:
|
||||
glDeleteTextures(1, &render->tx_mask);
|
||||
|
@ -100,7 +100,6 @@ void render_swap_and_blit(struct render *render)
|
||||
vertices[3*2+1] = t5;
|
||||
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
|
||||
// glFlush();
|
||||
|
||||
err1:
|
||||
eglMakeCurrent(render->dpy, draw, read, context);
|
||||
|
Loading…
Reference in New Issue
Block a user