File: test_mpi_opengl.h

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (212 lines) | stat: -rw-r--r-- 4,684 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* -*- c -*- *******************************************************/
/*
 * Copyright (C) 2015 Sandia Corporation
 * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
 * the U.S. Government retains certain rights in this software.
 *
 * This source code is released under the New BSD License.
 */

#ifndef _TEST_MPI_OPENGL_H
#define _TEST_MPI_OPENGL_H

#define ICET_NO_MPI_RENDERING_FUNCTIONS
#include "test_mpi.h"

#include "test_config.h"

#include <IceTGL.h>

#ifdef ICET_TESTS_USE_GLUT
#ifndef __APPLE__
#include <GL/glut.h>
#else
#include <GLUT/glut.h>
#endif
#endif

#ifdef ICET_TESTS_USE_GLFW
#include <GLFW/glfw3.h>
#endif

#ifdef ICET_TESTS_USE_GLUT
static int windowId;
#endif

#ifdef ICET_TESTS_USE_GLFW
static GLFWwindow *window;
#endif

#include "test_codes.h"

static void checkOglError(void)
{
    GLenum error = glGetError();

#define CASE_ERROR(ename)                                               \
    case ename: printrank("## Current IceT error = " #ename "\n"); break;

    switch (error) {
      case GL_NO_ERROR: break;
      CASE_ERROR(GL_INVALID_ENUM);
      CASE_ERROR(GL_INVALID_VALUE);
      CASE_ERROR(GL_INVALID_OPERATION);
      CASE_ERROR(GL_STACK_OVERFLOW);
      CASE_ERROR(GL_STACK_UNDERFLOW);
      CASE_ERROR(GL_OUT_OF_MEMORY);
#ifdef GL_TABLE_TOO_LARGE
      CASE_ERROR(GL_TABLE_TOO_LARGE);
#endif
      default:
          printrank("## UNKNOWN OPENGL ERROR CODE!!!!!!\n");
          break;
    }

#undef CASE_ERROR
}

void init_mpi_opengl(int *argcp, char ***argvp)
{
#ifdef ICET_TESTS_USE_GLUT
    /* Let Glut have first pass at the arguments to grab any that it can use. */
    glutInit(argcp, *argvp);
#endif

#ifdef ICET_TESTS_USE_GLFW
    if (!glfwInit()) { exit(1); }
#endif

    init_mpi(argcp, argvp);
}

#if defined(ICET_TESTS_USE_GLUT)
static int (*g_test_function)(void);

static void no_op()
{
}

static void glut_draw()
{
    int result;

    glEnable(GL_DEPTH_TEST);
    glViewport(0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT);
    glClear(GL_COLOR_BUFFER_BIT);
    swap_buffers();

    result = run_test_base(g_test_function);

    glutDestroyWindow(windowId);

    exit(result);
}

int run_test(int (*test_function)(void))
{
  /* Record the test function so we can run it in the Glut draw callback. */
    g_test_function = test_function;

    glutDisplayFunc(no_op);
    glutIdleFunc(glut_draw);

  /* Glut will reliably create the OpenGL context only after the main loop is
   * started.  This will create the window and then call our glut_draw function
   * to populate it.  It will never return, which is why we call exit in
   * glut_draw. */
    glutMainLoop();

  /* We do not expect to be here.  Raise an alert to signal that the tests are
   * not running as expected. */
    return TEST_NOT_PASSED;
}

void initialize_render_window(int width, int height)
{
    IceTInt rank, num_proc;

    icetGetIntegerv(ICET_RANK, &rank);
    icetGetIntegerv(ICET_NUM_PROCESSES, &num_proc);

    /* Create a renderable window. */
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(width, height);

    {
        char title[256];
        sprintf(title, "IceT Test %d of %d", rank, num_proc);
        windowId = glutCreateWindow(title);
    }

    icetGLInitialize();
}

void swap_buffers(void)
{
    glutSwapBuffers();
}

#elif defined(ICET_TESTS_USE_GLFW)

int run_test(int (*test_function)())
{
    int result;

    glEnable(GL_DEPTH_TEST);
    glViewport(0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT);
    glClear(GL_COLOR_BUFFER_BIT);
    swap_buffers();

    result = run_test_base(test_function);

    glfwDestroyWindow(window);
    glfwTerminate();

    return result;
}

void initialize_render_window(int width, int height)
{
    IceTInt rank, num_proc;

    icetGetIntegerv(ICET_RANK, &rank);
    icetGetIntegerv(ICET_NUM_PROCESSES, &num_proc);

    /* Create a renderable window. */
    glfwWindowHint(GLFW_RED_BITS, 8);
    glfwWindowHint(GLFW_GREEN_BITS, 8);
    glfwWindowHint(GLFW_BLUE_BITS, 8);
    glfwWindowHint(GLFW_ALPHA_BITS, 8);
    glfwWindowHint(GLFW_DEPTH_BITS, 24);
    glfwWindowHint(GLFW_SAMPLES, 0);

    {
        char title[256];
        sprintf(title, "IceT Test %d of %d", rank, num_proc);
        window = glfwCreateWindow(width, height, title, NULL, NULL);
    }

    glfwMakeContextCurrent(window);

    icetGLInitialize();
}

void swap_buffers(void)
{
    glfwSwapBuffers(window);
    glfwPollEvents();
}

#else

#error "ICET_TESTS_USE_OPENGL defined but no window library is defined."

#endif

void finalize_rendering()
{
    checkOglError();
}

#endif /* _TEST_MPI_OPENGL_H */