• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/minidlna/ffmpeg-2.3.4/libavdevice/

Lines Matching defs:opengl

279 static av_cold int opengl_init_context(OpenGLContext *opengl);
281 static av_cold void opengl_deinit_context(OpenGLContext *opengl)
283 glDeleteTextures(4, opengl->texture_name);
284 opengl->texture_name[0] = opengl->texture_name[1] =
285 opengl->texture_name[2] = opengl->texture_name[3] = 0;
286 if (opengl->glprocs.glUseProgram)
287 opengl->glprocs.glUseProgram(0);
288 if (opengl->glprocs.glDeleteProgram) {
289 opengl->glprocs.glDeleteProgram(opengl->program);
290 opengl->program = 0;
292 if (opengl->glprocs.glDeleteShader) {
293 opengl->glprocs.glDeleteShader(opengl->vertex_shader);
294 opengl->glprocs.glDeleteShader(opengl->fragment_shader);
295 opengl->vertex_shader = opengl->fragment_shader = 0;
297 if (opengl->glprocs.glBindBuffer) {
298 opengl->glprocs.glBindBuffer(FF_GL_ARRAY_BUFFER, 0);
299 opengl->glprocs.glBindBuffer(FF_GL_ELEMENT_ARRAY_BUFFER, 0);
301 if (opengl->glprocs.glDeleteBuffers) {
302 opengl->glprocs.glDeleteBuffers(2, &opengl->index_buffer);
303 opengl->vertex_buffer = opengl->index_buffer = 0;
310 OpenGLContext *opengl = h->priv_data;
311 opengl->window_width = width;
312 opengl->window_height = height;
313 if (opengl->inited) {
314 if (opengl->no_window &&
316 av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
329 OpenGLContext *opengl = h->priv_data;
338 return opengl_resize(h, opengl->window_width, opengl->window_height);
344 static int opengl_sdl_recreate_window(OpenGLContext *opengl, int width, int height)
346 opengl->surface = SDL_SetVideoMode(width, height,
348 if (!opengl->surface) {
349 av_log(opengl, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError());
363 OpenGLContext *opengl = h->priv_data;
385 opengl_deinit_context(opengl);
387 if ((ret = opengl_sdl_recreate_window(opengl, event.resize.w, event.resize.h)) < 0)
389 if (reinit && (ret = opengl_init_context(opengl)) < 0)
391 message.width = opengl->surface->w;
392 message.height = opengl->surface->h;
404 OpenGLContext *opengl = h->priv_data;
407 av_log(opengl, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError());
410 if ((ret = opengl_sdl_recreate_window(opengl, opengl->window_width,
411 opengl->window_height)) < 0)
413 av_log(opengl, AV_LOG_INFO, "SDL driver: '%s'.\n", SDL_VideoDriverName(buffer, sizeof(buffer)));
414 message.width = opengl->surface->w;
415 message.height = opengl->surface->h;
416 SDL_WM_SetCaption(opengl->window_title, NULL);
421 static int av_cold opengl_sdl_load_procedures(OpenGLContext *opengl)
423 FFOpenGLFunctions *procs = &opengl->glprocs;
428 av_log(opengl, AV_LOG_ERROR, "Cannot load OpenGL function: '%s'\n", #name); \
465 static int av_cold opengl_load_procedures(OpenGLContext *opengl)
467 FFOpenGLFunctions *procs = &opengl->glprocs;
470 if (!opengl->no_window)
471 return opengl_sdl_load_procedures(opengl);
502 static int av_cold opengl_load_procedures(OpenGLContext *opengl)
504 FFOpenGLFunctions *procs = &opengl->glprocs;
515 av_log(opengl, AV_LOG_ERROR, "Cannot load OpenGL function: '%s'\n", #name); \
520 if (!opengl->no_window)
521 return opengl_sdl_load_procedures(opengl);
583 static av_cold int opengl_read_limits(OpenGLContext *opengl)
603 av_log(opengl, AV_LOG_DEBUG, "OpenGL version: %s\n", version);
610 av_log(opengl, AV_LOG_ERROR, "Required extension %s is not supported.\n",
612 av_log(opengl, AV_LOG_DEBUG, "Supported extensions are: %s\n", extensions);
616 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &opengl->max_texture_size);
617 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, &opengl->max_viewport_width);
618 opengl->non_pow_2_textures = major >= 2 || strstr(extensions, "GL_ARB_texture_non_power_of_two");
620 opengl->unpack_subimage = !!strstr(extensions, "GL_EXT_unpack_subimage");
622 opengl->unpack_subimage = 1;
625 av_log(opengl, AV_LOG_DEBUG, "Non Power of 2 textures support: %s\n", opengl->non_pow_2_textures ? "Yes" : "No");
626 av_log(opengl, AV_LOG_DEBUG, "Unpack Subimage extension support: %s\n", opengl->unpack_subimage ? "Yes" : "No");
627 av_log(opengl, AV_LOG_DEBUG, "Max texture size: %dx%d\n", opengl->max_texture_size, opengl->max_texture_size);
628 av_log(opengl, AV_LOG_DEBUG, "Max viewport size: %dx%d\n",
629 opengl->max_viewport_width, opengl->max_viewport_height);
631 OPENGL_ERROR_CHECK(opengl);
663 static av_cold void opengl_get_texture_params(OpenGLContext *opengl)
667 if (opengl_format_desc[i].fixel_format == opengl->pix_fmt) {
668 opengl->format = opengl_format_desc[i].format;
669 opengl->type = opengl_format_desc[i].type;
678 OpenGLContext *opengl = s->priv_data;
688 if (av_cmp_q(dar, (AVRational){ opengl->window_width, opengl->window_height }) > 0) {
690 opengl->picture_width = opengl->window_width;
691 opengl->picture_height = av_rescale(opengl->picture_width, dar.den, dar.num);
694 opengl->picture_height = opengl->window_height;
695 opengl->picture_width = av_rescale(opengl->picture_height, dar.num, dar.den);
699 static av_cold void opengl_get_texture_size(OpenGLContext *opengl, int in_width, int in_height,
702 if (opengl->non_pow_2_textures) {
706 int max = FFMIN(FFMAX(in_width, in_height), opengl->max_texture_size);
712 av_log(opengl, AV_LOG_DEBUG, "Texture size calculated from %dx%d into %dx%d\n",
717 static av_cold void opengl_fill_color_map(OpenGLContext *opengl)
721 enum AVPixelFormat pix_fmt = opengl->pix_fmt;
736 opengl->color_map[(i << 2) + ((desc->comp[i].offset_plus1 - 1) >> shift)] = 1.0; \
739 memset(opengl->color_map, 0, sizeof(opengl->color_map));
749 static av_cold GLuint opengl_load_shader(OpenGLContext *opengl, GLenum type, const char *source)
751 GLuint shader = opengl->glprocs.glCreateShader(type);
754 av_log(opengl, AV_LOG_ERROR, "glCreateShader() failed\n");
757 opengl->glprocs.glShaderSource(shader, 1, &source, NULL);
758 opengl->glprocs.glCompileShader(shader);
760 opengl->glprocs.glGetShaderiv(shader, FF_GL_COMPILE_STATUS, &result);
763 opengl->glprocs.glGetShaderiv(shader, FF_GL_INFO_LOG_LENGTH, &result);
766 opengl->glprocs.glGetShaderInfoLog(shader, result, NULL, log);
767 av_log(opengl, AV_LOG_ERROR, "Compile error: %s\n", log);
773 OPENGL_ERROR_CHECK(opengl);
776 opengl->glprocs.glDeleteShader(shader);
780 static av_cold int opengl_compile_shaders(OpenGLContext *opengl, enum AVPixelFormat pix_fmt)
786 av_log(opengl, AV_LOG_ERROR, "Provided pixel format '%s' is not supported\n",
791 opengl->vertex_shader = opengl_load_shader(opengl, FF_GL_VERTEX_SHADER,
793 if (!opengl->vertex_shader) {
794 av_log(opengl, AV_LOG_ERROR, "Vertex shader loading failed.\n");
797 opengl->fragment_shader = opengl_load_shader(opengl, FF_GL_FRAGMENT_SHADER,
799 if (!opengl->fragment_shader) {
800 av_log(opengl, AV_LOG_ERROR, "Fragment shader loading failed.\n");
804 opengl->program = opengl->glprocs.glCreateProgram();
805 if (!opengl->program)
808 opengl->glprocs.glAttachShader(opengl->program, opengl->vertex_shader);
809 opengl->glprocs.glAttachShader(opengl->program, opengl->fragment_shader);
810 opengl->glprocs.glLinkProgram(opengl->program);
812 opengl->glprocs.glGetProgramiv(opengl->program, FF_GL_LINK_STATUS, &result);
815 opengl->glprocs.glGetProgramiv(opengl->program, FF_GL_INFO_LOG_LENGTH, &result);
820 opengl->glprocs.glGetProgramInfoLog(opengl->program, result, NULL, log);
821 av_log(opengl, AV_LOG_ERROR, "Link error: %s\n", log);
827 opengl->position_attrib = opengl->glprocs.glGetAttribLocation(opengl->program, "a_position");
828 opengl->texture_coords_attrib = opengl->glprocs.glGetAttribLocation(opengl->program, "a_textureCoords");
829 opengl->projection_matrix_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_projectionMatrix");
830 opengl->model_view_matrix_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_modelViewMatrix");
831 opengl->color_map_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_colorMap");
832 opengl->texture_location[0] = opengl->glprocs.glGetUniformLocation(opengl->program, "u_texture0");
833 opengl->texture_location[1] = opengl->glprocs.glGetUniformLocation(opengl->program, "u_texture1");
834 opengl->texture_location[2] = opengl->glprocs.glGetUniformLocation(opengl->program, "u_texture2");
835 opengl->texture_location[3] = opengl->glprocs.glGetUniformLocation(opengl->program, "u_texture3");
836 opengl->chroma_div_w_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_chroma_div_w");
837 opengl->chroma_div_h_location = opengl->glprocs.glGetUniformLocation(opengl->program, "u_chroma_div_h");
839 OPENGL_ERROR_CHECK(opengl);
842 opengl->glprocs.glDeleteShader(opengl->vertex_shader);
843 opengl->glprocs.glDeleteShader(opengl->fragment_shader);
844 opengl->glprocs.glDeleteProgram(opengl->program);
845 opengl->fragment_shader = opengl->vertex_shader = opengl->program = 0;
849 static av_cold int opengl_configure_texture(OpenGLContext *opengl, GLuint texture,
854 opengl_get_texture_size(opengl, width, height, &new_width, &new_height);
860 glTexImage2D(GL_TEXTURE_2D, 0, opengl->format, new_width, new_height, 0,
861 opengl->format, opengl->type, NULL);
871 OpenGLContext *opengl = s->priv_data;
874 if (opengl->window_width > opengl->max_viewport_width || opengl->window_height > opengl->max_viewport_height) {
875 opengl->window_width = FFMIN(opengl->window_width, opengl->max_viewport_width);
876 opengl->window_height = FFMIN(opengl->window_height, opengl->max_viewport_height);
877 av_log(opengl, AV_LOG_WARNING, "Too big viewport requested, limited to %dx%d", opengl->window_width, opengl->window_height);
879 glViewport(0, 0, opengl->window_width, opengl->window_height);
880 opengl_make_ortho(opengl->projection_matrix,
881 - (float)opengl->window_width / 2.0f, (float)opengl->window_width / 2.0f,
882 - (float)opengl->window_height / 2.0f, (float)opengl->window_height / 2.0f,
884 opengl_make_identity(opengl->model_view_matrix);
888 opengl->vertex[0].z = opengl->vertex[1].z = opengl->vertex[2].z = opengl->vertex[3].z = 0.0f;
889 opengl->vertex[0].x = opengl->vertex[1].x = - (float)opengl->picture_width / 2.0f;
890 opengl->vertex[2].x = opengl->vertex[3].x = (float)opengl->picture_width / 2.0f;
891 opengl->vertex[1].y = opengl->vertex[2].y = - (float)opengl->picture_height / 2.0f;
892 opengl->vertex[0].y = opengl->vertex[3].y = (float)opengl->picture_height / 2.0f;
894 opengl_get_texture_size(opengl, opengl->width, opengl->height, &tex_w, &tex_h);
896 opengl->vertex[0].s0 = 0.0f;
897 opengl->vertex[0].t0 = 0.0f;
898 opengl->vertex[1].s0 = 0.0f;
899 opengl->vertex[1].t0 = (float)opengl->height / (float)tex_h;
900 opengl->vertex[2].s0 = (float)opengl->width / (float)tex_w;
901 opengl->vertex[2].t0 = (float)opengl->height / (float)tex_h;
902 opengl->vertex[3].s0 = (float)opengl->width / (float)tex_w;
903 opengl->vertex[3].t0 = 0.0f;
905 opengl->glprocs.glBindBuffer(FF_GL_ARRAY_BUFFER, opengl->vertex_buffer);
906 opengl->glprocs.glBufferData(FF_GL_ARRAY_BUFFER, sizeof(opengl->vertex), opengl->vertex, FF_GL_STATIC_DRAW);
907 opengl->glprocs.glBindBuffer(FF_GL_ARRAY_BUFFER, 0);
908 OPENGL_ERROR_CHECK(opengl);
914 static int opengl_prepare(OpenGLContext *opengl)
917 opengl->glprocs.glUseProgram(opengl->program);
918 opengl->glprocs.glUniformMatrix4fv(opengl->projection_matrix_location, 1, GL_FALSE, opengl->projection_matrix);
919 opengl->glprocs.glUniformMatrix4fv(opengl->model_view_matrix_location, 1, GL_FALSE, opengl->model_view_matrix);
921 if (opengl->texture_location[i] != -1) {
922 opengl->glprocs.glActiveTexture(GL_TEXTURE0 + i);
923 glBindTexture(GL_TEXTURE_2D, opengl->texture_name[i]);
924 opengl->glprocs.glUniform1i(opengl->texture_location[i], i);
926 if (opengl->color_map_location != -1)
927 opengl->glprocs.glUniformMatrix4fv(opengl->color_map_location, 1, GL_FALSE, opengl->color_map);
928 if (opengl->chroma_div_h_location != -1)
929 opengl->glprocs.glUniform1f(opengl->chroma_div_h_location, opengl->chroma_div_h);
930 if (opengl->chroma_div_w_location != -1)
931 opengl->glprocs.glUniform1f(opengl->chroma_div_w_location, opengl->chroma_div_w);
933 OPENGL_ERROR_CHECK(opengl);
941 OpenGLContext *opengl = h->priv_data;
944 if (!opengl->no_window) {
947 av_log(opengl, AV_LOG_ERROR, "Cannot create default SDL window.\n");
951 av_log(opengl, AV_LOG_ERROR, "FFmpeg is compiled without SDL. Cannot create default window.\n");
957 message.width = opengl->window_width;
958 message.height = opengl->window_height;
961 av_log(opengl, AV_LOG_ERROR, "Application failed to create window buffer.\n");
965 av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
975 OpenGLContext *opengl = h->priv_data;
976 if (!opengl->no_window) {
981 av_log(opengl, AV_LOG_ERROR, "Application failed to release window buffer.\n");
989 OpenGLContext *opengl = h->priv_data;
991 if (opengl->no_window &&
993 av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
995 opengl_deinit_context(opengl);
1001 static av_cold int opengl_init_context(OpenGLContext *opengl)
1006 if ((ret = opengl_compile_shaders(opengl, opengl->pix_fmt)) < 0)
1009 desc = av_pix_fmt_desc_get(opengl->pix_fmt);
1011 glGenTextures(desc->nb_components, opengl->texture_name);
1013 opengl->glprocs.glGenBuffers(2, &opengl->index_buffer);
1014 if (!opengl->index_buffer || !opengl->vertex_buffer) {
1015 av_log(opengl, AV_LOG_ERROR, "Buffer generation failed.\n");
1020 opengl_configure_texture(opengl, opengl->texture_name[0], opengl->width, opengl->height);
1024 if (opengl->non_pow_2_textures) {
1025 opengl->chroma_div_w = 1.0f;
1026 opengl->chroma_div_h = 1.0f;
1028 opengl->chroma_div_w = 1 << desc->log2_chroma_w;
1029 opengl->chroma_div_h = 1 << desc->log2_chroma_h;
1032 if (opengl->non_pow_2_textures)
1033 opengl_configure_texture(opengl, opengl->texture_name[i],
1034 FF_CEIL_RSHIFT(opengl->width, desc->log2_chroma_w),
1035 FF_CEIL_RSHIFT(opengl->height, desc->log2_chroma_h));
1037 opengl_configure_texture(opengl, opengl->texture_name[i], opengl->width, opengl->height);
1039 opengl_configure_texture(opengl, opengl->texture_name[3], opengl->width, opengl->height);
1042 opengl->glprocs.glBindBuffer(FF_GL_ELEMENT_ARRAY_BUFFER, opengl->index_buffer);
1043 opengl->glprocs.glBufferData(FF_GL_ELEMENT_ARRAY_BUFFER, sizeof(g_index), g_index, FF_GL_STATIC_DRAW);
1044 opengl->glprocs.glBindBuffer(FF_GL_ELEMENT_ARRAY_BUFFER, 0);
1049 glClearColor((float)opengl->background[0] / 255.0f, (float)opengl->background[1] / 255.0f,
1050 (float)opengl->background[2] / 255.0f, 1.0f);
1053 OPENGL_ERROR_CHECK(opengl);
1062 OpenGLContext *opengl = h->priv_data;
1069 av_log(opengl, AV_LOG_ERROR, "Only a single video stream is supported.\n");
1073 opengl->width = st->codec->width;
1074 opengl->height = st->codec->height;
1075 opengl->pix_fmt = st->codec->pix_fmt;
1076 if (!opengl->window_width)
1077 opengl->window_width = opengl->width;
1078 if (!opengl->window_height)
1079 opengl->window_height = opengl->height;
1081 if (!opengl->window_title && !opengl->no_window)
1082 opengl->window_title = av_strdup(h->filename);
1087 if ((ret = opengl_read_limits(opengl)) < 0)
1090 if (opengl->width > opengl->max_texture_size || opengl->height > opengl->max_texture_size) {
1091 av_log(opengl, AV_LOG_ERROR, "Too big picture %dx%d, max supported size is %dx%d\n",
1092 opengl->width, opengl->height, opengl->max_texture_size, opengl->max_texture_size);
1097 if ((ret = opengl_load_procedures(opengl)) < 0)
1100 opengl_fill_color_map(opengl);
1101 opengl_get_texture_params(opengl);
1103 if ((ret = opengl_init_context(opengl)) < 0)
1112 if (!opengl->no_window)
1115 if (opengl->no_window &&
1117 av_log(opengl, AV_LOG_ERROR, "Application failed to display window buffer.\n");
1122 OPENGL_ERROR_CHECK(opengl);
1124 opengl->inited = 1;
1132 static uint8_t* opengl_get_plane_pointer(OpenGLContext *opengl, AVPacket *pkt, int comp_index,
1136 int wordsize = opengl_type_size(opengl->type);
1137 int width_chroma = FF_CEIL_RSHIFT(opengl->width, desc->log2_chroma_w);
1138 int height_chroma = FF_CEIL_RSHIFT(opengl->height, desc->log2_chroma_h);
1145 data += opengl->width * opengl->height * wordsize;
1148 data += opengl->width * opengl->height * wordsize;
1152 data += opengl->width * opengl->height * wordsize;
1163 int width = sub ? FF_CEIL_RSHIFT(opengl->width, desc->log2_chroma_w) : opengl->width; \
1164 int height = sub ? FF_CEIL_RSHIFT(opengl->height, desc->log2_chroma_h): opengl->height; \
1168 glBindTexture(GL_TEXTURE_2D, opengl->texture_name[comp_index]); \
1171 int bytes_per_pixel = opengl_type_size(opengl->type); \
1176 (opengl->unpack_subimage || ((length / bytes_per_pixel) == width))) { \
1181 opengl->format, opengl->type, data); \
1188 opengl->format, opengl->type, data); \
1193 data = opengl_get_plane_pointer(opengl, input, comp_index, desc); \
1195 opengl->format, opengl->type, data); \
1201 OpenGLContext *opengl = h->priv_data;
1207 if (!opengl->no_window && (ret = opengl_sdl_process_events(h)) < 0)
1210 if (opengl->no_window &&
1212 av_log(opengl, AV_LOG_ERROR, "Application failed to prepare window buffer.\n");
1230 OPENGL_ERROR_CHECK(opengl);
1232 if ((ret = opengl_prepare(opengl)) < 0)
1235 opengl->glprocs.glBindBuffer(FF_GL_ARRAY_BUFFER, opengl->vertex_buffer);
1236 opengl->glprocs.glBindBuffer(FF_GL_ELEMENT_ARRAY_BUFFER, opengl->index_buffer);
1237 opengl->glprocs.glVertexAttribPointer(opengl->position_attrib, 3, GL_FLOAT, GL_FALSE, sizeof(OpenGLVertexInfo), 0);
1238 opengl->glprocs.glEnableVertexAttribArray(opengl->position_attrib);
1239 opengl->glprocs.glVertexAttribPointer(opengl->texture_coords_attrib, 2, GL_FLOAT, GL_FALSE, sizeof(OpenGLVertexInfo), 12);
1240 opengl->glprocs.glEnableVertexAttribArray(opengl->texture_coords_attrib);
1245 OPENGL_ERROR_CHECK(opengl);
1248 if (!opengl->no_window)
1251 if (opengl->no_window &&
1253 av_log(opengl, AV_LOG_ERROR, "Application failed to display window buffer.\n");
1286 .class_name = "opengl outdev",
1294 .name = "opengl",