UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
dxt_util.c File Reference
#include "dxt_common.h"
#include "dxt_util.h"
Include dependency graph for dxt_util.c:

Go to the source code of this file.

Functions

GLuint dxt_shader_create_from_file (const char *filename, GLenum type)
 
GLuint dxt_shader_create_from_source (const char *source, GLenum type)
 

Function Documentation

◆ dxt_shader_create_from_file()

GLuint dxt_shader_create_from_file ( const char * filename,
GLenum type )

Documented at declaration

Definition at line 56 of file dxt_util.c.

57{
58 // Load program from file
59 FILE* file;
60 file = fopen(filename, "r");
61 if ( !file ) {
62 fprintf(stderr, "Failed open %s for reading!\n", filename);
63 return 0;
64 }
65 fseek(file, 0, SEEK_END);
66 int data_size = ftell(file);
67 assert(data_size >= 0);
68 rewind(file);
69 char* program = (char*)malloc((data_size + 1) * sizeof(char));
70 if ( (size_t) data_size != fread(program, sizeof(char), data_size, file) ) {
71 fprintf(stderr, "Failed to load program [%d bytes] from file %s!\n", data_size, filename);
72 free(program);
73 fclose(file);
74 return 0;
75 }
76 fclose(file);
77 program[data_size] = '\0';
78
79 printf("Compiling program [%s]...\n", filename);
80 GLuint shader = dxt_shader_create_from_source(program, type);
81 if ( shader == 0 ) {
82 free(program);
83 return 0;
84 }
85
86 free(program);
87
88 return shader;
89}
GLuint dxt_shader_create_from_source(const char *source, GLenum type)
Definition dxt_util.c:32
Option::OptType type
Definition settings.cpp:194

References dxt_shader_create_from_source(), and type.

Here is the call graph for this function:

◆ dxt_shader_create_from_source()

GLuint dxt_shader_create_from_source ( const char * source,
GLenum type )

Copyright (c) 2011, Martin Srom All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Documented at declaration

Definition at line 32 of file dxt_util.c.

33{
34 // Create shader
35 GLuint shader = glCreateShader(type);
36
37 // Compile shader source
38 glShaderSource(shader, 1, (const GLchar**)&source, NULL);
39 glCompileShader(shader);
40
41 // Check result
42 GLint status;
43 glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
44 if ( status == GL_FALSE ) {
45 char log[32768];
46 glGetShaderInfoLog(shader, 32768, NULL, (GLchar*)log);
47 printf("Shader Compilation Failed : %s\n", log);
48 return 0;
49 }
50
51 return shader;
52}
Definition rtp.c:206

References type.

Referenced by dxt_decoder_create(), dxt_display_init(), dxt_encoder_create(), dxt_prepare_yuv422_shader(), and dxt_shader_create_from_file().