File: webgl_shader_source_length.cpp

package info (click to toggle)
emscripten 3.1.6~dfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 114,112 kB
  • sloc: ansic: 583,052; cpp: 391,943; javascript: 79,361; python: 54,180; sh: 49,997; pascal: 4,658; makefile: 3,426; asm: 2,191; lisp: 1,869; ruby: 488; cs: 142
file content (67 lines) | stat: -rw-r--r-- 1,907 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2017 The Emscripten Authors.  All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License.  Both these licenses can be
// found in the LICENSE file.

#define GL_GLEXT_PROTOTYPES
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLES2/gl2.h>
#include <stdio.h>
#include <emscripten.h>
#include <emscripten/html5.h>
#include <assert.h>
#include <string.h>

#define GL_CALL( x ) \
    { \
        x; \
        GLenum error = glGetError(); \
        if( error != GL_NO_ERROR ) { \
            printf( "GL ERROR: %d,  %s\n", (int)error, #x ); \
            assert(false); \
        } \
    } \


int main()
{
  emscripten_set_canvas_element_size( "#canvas", 100, 100 );

  EmscriptenWebGLContextAttributes attrs;
  emscripten_webgl_init_context_attributes(&attrs);

  EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context( "#canvas", &attrs );
  if (!context)
  {
    printf("Skipped: WebGL is not supported.\n");
    return 0;
  }
  emscripten_webgl_make_context_current(context);

  GLuint shader;
  GL_CALL( shader = glCreateShader(GL_VERTEX_SHADER) );

  GLint value = -97631;
  GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
  assert(value == 0);

  const GLchar* tempSource = (const GLchar*)"";
  GL_CALL( glShaderSource(shader, 1, &tempSource, NULL) );

  value = -97631;
  GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
  assert(value == 0);

  tempSource = (const GLchar*)"void main() { gl_Position = vec4(0); }";
  GL_CALL( glShaderSource(shader, 1, &tempSource, NULL) );

  value = -97631;
  GL_CALL( glGetShaderiv(shader, GL_SHADER_SOURCE_LENGTH, &value) );
  assert(value == strlen(tempSource) + 1);

  EMSCRIPTEN_RESULT res = emscripten_webgl_destroy_context(context);
  assert(res == EMSCRIPTEN_RESULT_SUCCESS);

  return 0;
}