Пример #1
0
GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, const GLUSint width, const GLUSint height, const EGLint* attribList, const GLUSboolean fullscreen)
{
	EGLConfig eglConfig;

	EGLint eglNativeVisualID;

	EGLNativeWindowType eglNativeWindowType;

	if (g_windowCreated)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Window already exists");

		return GLUS_FALSE;
	}

	if (!glusEGLCreateContext(_glusGetNativeDisplayType(), &g_eglDisplay, &eglConfig, &g_eglContext, attribList, g_eglContextClientVersion))
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could preinitialize EGL");

		glusDestroyWindow();

		return GLUS_FALSE;
	}

	if (!glusEGLGetNativeVisualID(g_eglDisplay, eglConfig, &eglNativeVisualID))
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not get native visual ID");

		glusDestroyWindow();

		return GLUS_FALSE;
	}

	eglNativeWindowType = _glusCreateNativeWindowType(title, width, height, fullscreen, g_noResize, eglNativeVisualID);

	if (!eglNativeWindowType)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not create native window");

		glusDestroyWindow();

		return GLUS_FALSE;
	}

	if (!glusEGLCreateWindowSurfaceMakeCurrent(eglNativeWindowType, &g_eglDisplay, &eglConfig, &g_eglContext, &g_eglSurface))
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not post initialize EGL");

		glusDestroyWindow();

		return GLUS_FALSE;
	}

	_glusGetWindowSize(&g_width, &g_height);

	g_windowCreated = GLUS_TRUE;

	return GLUS_TRUE; // Success
}
Пример #2
0
void Matrix4x4::debugOut() const
{
	glusLogPrint(GLUS_LOG_DEBUG, "Matrix4x4:");
	glusLogPrint(GLUS_LOG_DEBUG, "%f %f %f %f", m[0], m[4], m[8], m[12]);
	glusLogPrint(GLUS_LOG_DEBUG, "%f %f %f %f", m[1], m[5], m[9], m[13]);
	glusLogPrint(GLUS_LOG_DEBUG, "%f %f %f %f", m[2], m[6], m[10], m[14]);
	glusLogPrint(GLUS_LOG_DEBUG, "%f %f %f %f", m[3], m[7], m[11], m[15]);
}
Пример #3
0
GLUSboolean GLUSAPIENTRY glusCreateComputeProgramFromSource(GLUSshaderprogram* shaderProgram, const GLUSchar** computeSource)
{
    GLUSint compiled;

    GLUSint logLength, charsWritten;

    char* log;

    if (!shaderProgram || !computeSource)
    {
        return GLUS_FALSE;
    }

    shaderProgram->program = 0;
    shaderProgram->compute = 0;
    shaderProgram->vertex = 0;
    shaderProgram->control = 0;
    shaderProgram->evaluation = 0;
    shaderProgram->geometry = 0;
    shaderProgram->fragment = 0;

    shaderProgram->compute = glCreateShader(GLUS_COMPUTE_SHADER);

    glShaderSource(shaderProgram->compute, 1, (const char**) computeSource, 0);

    glCompileShader(shaderProgram->compute);

    glGetShaderiv(shaderProgram->compute, GL_COMPILE_STATUS, &compiled);

    if (!compiled)
    {
        glGetShaderiv(shaderProgram->compute, GL_INFO_LOG_LENGTH, &logLength);

        log = (char*) malloc((size_t)logLength);

        if (!log)
        {
            return GLUS_FALSE;
        }

        glGetShaderInfoLog(shaderProgram->compute, logLength, &charsWritten, log);

        glusLogPrint(GLUS_LOG_ERROR, "Compute shader compile error:");
        glusLogPrint(GLUS_LOG_ERROR, "%s", log);

        free(log);

        shaderProgram->compute = 0;

        return GLUS_FALSE;
    }

    shaderProgram->program = glCreateProgram();

    glAttachShader(shaderProgram->program, shaderProgram->compute);

    return GLUS_TRUE;
}
Пример #4
0
EGLNativeWindowType _glusOsCreateNativeWindowType(const char* title, const GLUSint width, const GLUSint height, const GLUSboolean fullscreen, const GLUSboolean noResize, EGLint eglNativeVisualID)
{
	glusLogPrint(GLUS_LOG_INFO, "Parameters 'title', 'width', 'height', 'fullscreen' and 'noResize' are not used");
	glusLogPrint(GLUS_LOG_INFO, "Key and mouse events are not supported");

	// Width and height already set.

	return g_nativeWindow;
}
GLUSboolean GLUSAPIENTRY glusBuildShaderProgramFromSource(GLUSshaderprogram* shaderProgram, const GLUSenum type, const GLUSchar** source)
{
    GLUSint linked;

    GLUSint logLength, charsWritten;

    char* log;

    if (!shaderProgram || !source)
    {
        return GLUS_FALSE;
    }

    shaderProgram->program = 0;
    shaderProgram->compute = 0;
    shaderProgram->vertex = 0;
    shaderProgram->fragment = 0;

    shaderProgram->program = glCreateShaderProgramv(type, 1, (const char**)source);

    glGetProgramiv(shaderProgram->program, GL_LINK_STATUS, &linked);

    if (!linked)
    {
        glGetProgramiv(shaderProgram->program, GL_INFO_LOG_LENGTH, &logLength);

        log = (char*) malloc((size_t)logLength);

        if (!log)
        {
            glusDestroyProgram(shaderProgram);

            return GLUS_FALSE;
        }

        glGetProgramInfoLog(shaderProgram->program, logLength, &charsWritten, log);

        glusLogPrint(GLUS_LOG_ERROR, "Shader program link error:");
        glusLogPrint(GLUS_LOG_ERROR, "%s", log);

        free(log);

        shaderProgram->program = 0;

        glusDestroyProgram(shaderProgram);

        return GLUS_FALSE;
    }

    return GLUS_TRUE;
}
Пример #6
0
GLUSboolean GLUSAPIENTRY glusWindowCreate(const GLUSchar* title, const GLUSint width, const GLUSint height, const GLUSboolean fullscreen, const GLUSboolean noResize, const EGLint* configAttribList, const EGLint* contextAttribList, const EGLint* surfaceAttribList)
{
	EGLConfig eglConfig;

	EGLNativeWindowType eglNativeWindowType;

	EGLint nativeVisualID = 0;

	if (g_windowCreated)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Window already exists");

		return GLUS_FALSE;
	}

	if (!glusEGLCreateContext(_glusOsGetNativeDisplayType(), &g_eglDisplay, &eglConfig, &g_eglContext, configAttribList, contextAttribList))
	{
		glusWindowDestroy();

		return GLUS_FALSE;
	}

	eglGetConfigAttrib(g_eglDisplay, eglConfig, EGL_NATIVE_VISUAL_ID, &nativeVisualID);

	eglNativeWindowType = _glusOsCreateNativeWindowType(title, width, height, fullscreen, noResize, nativeVisualID);

	if (!eglNativeWindowType)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not create native window");

		glusWindowDestroy();

		return GLUS_FALSE;
	}

	if (!glusEGLCreateWindowSurfaceMakeCurrent(eglNativeWindowType, &g_eglDisplay, &eglConfig, &g_eglContext, &g_eglSurface, surfaceAttribList))
	{
		glusWindowDestroy();

		return GLUS_FALSE;
	}

	_glusOsGetWindowSize(&g_width, &g_height);

	g_windowCreated = GLUS_TRUE;

	return GLUS_TRUE; // Success
}
Пример #7
0
GLvoid GLUSAPIENTRY glusEGLTerminate(EGLDisplay* eglDisplay, EGLContext* eglContext, EGLSurface* eglSurface)
{
    if (!eglDisplay)
    {
    	glusLogPrint(GLUS_LOG_ERROR, "No eglDisplay passed");

        return;
    }

    if (*eglDisplay)
    {
        eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);

        if (eglSurface && *eglSurface)
        {
            eglDestroySurface(eglDisplay, *eglSurface);

            *eglSurface = EGL_NO_SURFACE;
        }

        if (eglContext && *eglContext)
        {
            eglDestroyContext(eglDisplay, *eglContext);

            *eglContext = EGL_NO_CONTEXT;
        }

        eglTerminate(*eglDisplay);

        *eglDisplay = EGL_NO_DISPLAY;
    }
}
GLUSboolean GLUSAPIENTRY glusLinkProgram(GLUSshaderprogram* shaderProgram)
{
    GLUSint linked;

    GLUSint logLength, charsWritten;

    char* log;

    if (!shaderProgram)
    {
        return GLUS_FALSE;
    }

    glLinkProgram(shaderProgram->program);

    glGetProgramiv(shaderProgram->program, GL_LINK_STATUS, &linked);

    if (!linked)
    {
        glGetProgramiv(shaderProgram->program, GL_INFO_LOG_LENGTH, &logLength);

        log = (char*) malloc((size_t)logLength);

        if (!log)
        {
            glusDestroyProgram(shaderProgram);

            return GLUS_FALSE;
        }

        glGetProgramInfoLog(shaderProgram->program, logLength, &charsWritten, log);

        glusLogPrint(GLUS_LOG_ERROR, "Shader program link error:");
        glusLogPrint(GLUS_LOG_ERROR, "%s", log);

        free(log);

        shaderProgram->program = 0;

        glusDestroyProgram(shaderProgram);

        return GLUS_FALSE;
    }

    return GLUS_TRUE;
}
Пример #9
0
EGLBoolean GLUSAPIENTRY glusEGLCreateWindowSurfaceMakeCurrent(EGLNativeWindowType eglNativeWindowType, EGLDisplay* eglDisplay, EGLConfig* eglConfig, EGLContext* eglContext, EGLSurface* eglSurface)
{
    EGLDisplay surface = EGL_NO_SURFACE;

    if (!eglDisplay || !eglConfig || !eglContext || !eglSurface)
    {
        glusLogPrint(GLUS_LOG_ERROR, "No eglDisplay, eglConfig, eglContext or eglSurface passed");

        return EGL_FALSE;
    }

    // Create a surface
    surface = eglCreateWindowSurface(*eglDisplay, *eglConfig, (EGLNativeWindowType) eglNativeWindowType, 0);
    if (surface == EGL_NO_SURFACE)
    {
        glusLogPrint(GLUS_LOG_ERROR, "Could not create EGL window surface");

        glusEGLTerminate(eglDisplay, eglContext, 0);

        return EGL_FALSE;
    }

    // Make the context current
    if (!eglMakeCurrent(*eglDisplay, surface, surface, *eglContext))
    {
        glusLogPrint(GLUS_LOG_ERROR, "Could not set EGL context as current");

        glusEGLTerminate(eglDisplay, eglContext, 0);

        return EGL_FALSE;
    }

    *eglSurface = surface;

    return EGL_TRUE;
}
Пример #10
0
EGLNativeDisplayType _glusOsGetNativeDisplayType()
{
	if (g_nativeDisplay != 0)
	{
		return g_nativeDisplay;
	}

	g_nativeDisplay = fbGetDisplayByIndex(0);

	if (g_nativeDisplay == 0)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not get native display");

		return 0;
	}

	fbGetDisplayGeometry(g_nativeDisplay, &g_displayWidth, &g_displayHeight);

	return g_nativeDisplay;
}
Пример #11
0
GLUSboolean GLUSAPIENTRY glusProfileUpdateFPSf(GLUSfloat time, GLUSuint* frames)
{
	passedTime += time;
	passedFrames++;

	if (passedTime >= 1.0f)
	{
		if (frames)
		{
			*frames = passedFrames;
		}
		else
		{
			glusLogPrint(GLUS_LOG_INFO, "FPS: %d", passedFrames);
		}

		glusProfileResetFPSf();

		return GLUS_TRUE;
	}

	return GLUS_FALSE;
}
Пример #12
0
EGLNativeWindowType _glusOsCreateNativeWindowType(const char* title, const GLUSint width, const GLUSint height, const GLUSboolean fullscreen, const GLUSboolean noResize, EGLint eglNativeVisualID)
{
	glusLogPrint(GLUS_LOG_INFO, "Parameters 'title', 'fullscreen' and 'noResize' are not used");
	glusLogPrint(GLUS_LOG_INFO, "Key events are mapped to US keyboard");
	glusLogPrint(GLUS_LOG_INFO, "Touch display is used for mouse events and are limited");

	g_keyFileDescriptor = open("/dev/input/event5", O_RDONLY | O_NONBLOCK);

	if (g_keyFileDescriptor < 0)
	{
		glusLogPrint(GLUS_LOG_WARNING, "Could not open key input device");
	}
	else
	{
		// Disable echo.
		system("stty -echo");
	}

	g_touchFileDescriptor = open("/dev/input/event0", O_RDONLY | O_NONBLOCK);

	if (g_touchFileDescriptor < 0)
	{
		glusLogPrint(GLUS_LOG_WARNING, "Could not open touch input device");
	}

	g_nativeWindow = fbCreateWindow(g_nativeDisplay, 0, 0, width, height);

	if (g_nativeWindow == 0)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not create native window");

		return 0;
	}

	g_width = width;
	g_height = height;

	return g_nativeWindow;
}
Пример #13
0
GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, const GLUSint width, const GLUSint height, const GLUSint depthBits, const GLUSint stencilBits, const GLUSboolean fullscreen)
{
	GLUSenum err;

	if (g_window)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Window already exists");

		return GLUS_FALSE;
	}

	if (!glfwInit())
	{
		glusLogPrint(GLUS_LOG_ERROR, "GLFW could not be initialized");

		return GLUS_FALSE;
	}

	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, g_major);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, g_minor);
	glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, g_flags & GLUS_FORWARD_COMPATIBLE_BIT);
	glfwWindowHint(GLFW_OPENGL_PROFILE, (g_flags & GLUS_FORWARD_COMPATIBLE_BIT) ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE);
	glfwWindowHint(GLFW_SAMPLES, g_numberSamples);
	glfwWindowHint(GLFW_RESIZABLE, !g_noResize);
	glfwWindowHint(GLFW_DEPTH_BITS, depthBits);
	glfwWindowHint(GLFW_STENCIL_BITS, stencilBits);
	glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, g_debug || (g_flags & GLUS_DEBUG_CONTEXT_BIT));

	g_window = glfwCreateWindow(width, height, title, fullscreen ? glfwGetPrimaryMonitor() : 0, 0);
	if (!g_window)
	{
		glfwTerminate();

		glusLogPrint(GLUS_LOG_ERROR, "GLFW window could not be opened");

		return GLUS_FALSE;
	}

	glfwMakeContextCurrent(g_window);

	glewExperimental = GLUS_TRUE;

	err = glewInit();

	if (GLUS_OK != err)
	{
		glusDestroyWindow();

		glusLogPrint(GLUS_LOG_ERROR, "GLEW could not be initialized: %x", err);

		return GLUS_FALSE;
	}

	// Catch all OpenGL errors so far.
	glGetError();

	if (!glusIsSupported(g_major, g_minor))
	{
		glusDestroyWindow();

		glusLogPrint(GLUS_LOG_ERROR, "OpenGL %u.%u not supported", g_major, g_minor);

		return GLUS_FALSE;
	}

	glfwSetWindowSizeCallback(g_window, glusInternalReshape);
	glfwSetWindowCloseCallback(g_window, glusInternalClose);
	glfwSetKeyCallback(g_window, glusInternalKey);
	glfwSetMouseButtonCallback(g_window, glusInternalMouse);
	glfwSetScrollCallback(g_window, glusInternalMouseWheel);
	glfwSetCursorPosCallback(g_window, glusInternalMouseMove);

	glfwGetWindowSize(g_window, &g_width, &g_height);

	if (g_debug && glusIsSupported(4, 3))
	{
		glusLogSetLevel(GLUS_LOG_DEBUG);

		glDebugMessageCallback(&glusInternalDebugMessage, 0);
	}

	return GLUS_TRUE; // Success
}
Пример #14
0
static GLUSvoid APIENTRY glusInternalDebugMessage(GLUSenum source, GLUSenum type, GLUSuint id, GLUSenum severity, GLUSsizei length, const GLUSchar* message, GLUSvoid* userParam)
{
	glusLogPrint(GLUS_LOG_DEBUG, "source: 0x%04X type: 0x%04X id: %u severity: 0x%04X '%s'", source, type, id, severity, message);
}
Пример #15
0
EGLNativeWindowType _glusOsCreateNativeWindowType(const char* title, const GLUSint width, const GLUSint height, const GLUSboolean fullscreen, const GLUSboolean noResize, EGLint eglNativeVisualID)
{
	char eventFilename[256];
	int eventNumber;

	int fileDescriptor;

	uint32_t eventBits;

	glusLogPrint(GLUS_LOG_INFO, "Parameters 'title', 'fullscreen' and 'noResize' are not used");
	glusLogPrint(GLUS_LOG_INFO, "Key events are mapped to US keyboard");
	glusLogPrint(GLUS_LOG_INFO, "Touch display is used for mouse events and are limited");

	strcpy(eventFilename, "/dev/input/event0");

	for (eventNumber = 0; eventNumber < 10; eventNumber++)
	{
		eventFilename[16] = '0' + (char)eventNumber;

		fileDescriptor = open(eventFilename, O_RDONLY | O_NONBLOCK);

		if (fileDescriptor < 0)
		{
			continue;
		}

		eventBits = 0;
		if (ioctl(fileDescriptor, EVIOCGBIT(0, EV_MAX), &eventBits) < 0)
		{
			close(fileDescriptor);

			continue;
		}

		if (eventBits == 0x120013 && g_keyFileDescriptor < 0)
		{
			glusLogPrint(GLUS_LOG_INFO, "Found keyboard on '%s'", eventFilename);

			g_keyFileDescriptor = fileDescriptor;

			// Disable echo.
			system("stty -echo");
		}
		else if (eventBits == 0x17 && g_powermateFileDescriptor < 0)
		{
			glusLogPrint(GLUS_LOG_INFO, "Found power mate on '%s'", eventFilename);

			g_powermateFileDescriptor = fileDescriptor;
		}
		else if (eventBits == 0xb && g_touchFileDescriptor < 0)
		{
			glusLogPrint(GLUS_LOG_INFO, "Found touch display on '%s'", eventFilename);

			g_touchFileDescriptor = fileDescriptor;
		}
		else
		{
			close(fileDescriptor);
		}
	}

	g_nativeWindow = fbCreateWindow(g_nativeDisplay, 0, 0, width, height);

	if (g_nativeWindow == 0)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not create native window");

		return 0;
	}

	g_width = width;
	g_height = height;

	return g_nativeWindow;
}
Пример #16
0
GLUSboolean GLUSAPIENTRY glusShapeCreateAdjacencyIndicesf(GLUSshape* adjacencyShape, const GLUSshape* sourceShape)
{
	GLUSuint i;

	GLUSuint numberIndices;

	GLUSuint adjacentIndex, edge;

	if (!adjacencyShape || !sourceShape)
	{
		return GLUS_FALSE;
	}

	if (sourceShape->mode != GLUS_TRIANGLES)
	{
		return GLUS_FALSE;
	}

	numberIndices = sourceShape->numberIndices * 2;

	if (numberIndices > GLUS_MAX_INDICES)
	{
		return GLUS_FALSE;
	}

	if (!glusShapeCopyf(adjacencyShape, sourceShape))
	{
		glusShapeDestroyf(adjacencyShape);

		return GLUS_FALSE;
	}

	adjacencyShape->numberIndices = numberIndices;

	glusMemoryFree(adjacencyShape->indices);
	adjacencyShape->indices = (GLUSuint*)glusMemoryMalloc(numberIndices * sizeof(GLUSuint));

	adjacencyShape->mode = GLUS_TRIANGLES_ADJACENCY;

	if (!glusShapeCheckCompletef(adjacencyShape))
	{
		glusShapeDestroyf(adjacencyShape);

		return GLUS_FALSE;
	}

	// Process all triangles
	for (i = 0; i < sourceShape->numberIndices / 3; i++)
	{
		// For now, all adjacent triangles are degenerated.
		adjacencyShape->indices[6 * i + 0] = sourceShape->indices[3 * i + 0];
		adjacencyShape->indices[6 * i + 1] = sourceShape->indices[3 * i + 0];
		adjacencyShape->indices[6 * i + 2] = sourceShape->indices[3 * i + 1];
		adjacencyShape->indices[6 * i + 3] = sourceShape->indices[3 * i + 1];
		adjacencyShape->indices[6 * i + 4] = sourceShape->indices[3 * i + 2];
		adjacencyShape->indices[6 * i + 5] = sourceShape->indices[3 * i + 2];

		// Skip degenerated triangles
		if (sourceShape->indices[i * 3 + 0] == sourceShape->indices[i * 3 + 1] || sourceShape->indices[i * 3 + 0] == sourceShape->indices[i * 3 + 2] || sourceShape->indices[i * 3 + 1] == sourceShape->indices[i * 3 + 2])
		{
			continue;
		}

		// Find adjacent indices for each edge of the triangle ...
		for (edge = 0; edge < 3; edge++)
		{
			adjacentIndex = 0;

			// ... by scanning the indices ...
			if (glusShapeFindIndexByIndicesf(&adjacentIndex, 3 * i, edge, sourceShape))
			{
				adjacencyShape->indices[6 * i + edge * 2 + 1] = adjacentIndex;

				continue;
			}

			// ... and if not found, compare the vertices.
			if (glusShapeFindIndexByVerticesf(&adjacentIndex, 3 * i, edge, sourceShape))
			{
				adjacencyShape->indices[6 * i + edge * 2 + 1] = adjacentIndex;

				continue;
			}

			glusLogPrint(GLUS_LOG_WARNING, "Triangle %d with edge %d: No adjacent index found!", i, edge);
		}
	}

	return GLUS_TRUE;
}
Пример #17
0
EGLBoolean GLUSAPIENTRY glusEGLCreateContext(EGLNativeDisplayType eglNativeDisplayType, EGLDisplay* eglDisplay, EGLConfig* eglConfig, EGLContext *eglContext,  const EGLint attribList[], const EGLint eglContextClientVersion)
{
    EGLint numConfigs;
    EGLint majorVersion;
    EGLint minorVersion;
    EGLDisplay display = EGL_NO_DISPLAY;
    EGLConfig config = 0;
    EGLDisplay context = EGL_NO_CONTEXT;

    EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, GLUS_DEFAULT_CLIENT_VERSION, EGL_NONE, EGL_NONE };

    if (!eglDisplay || !eglConfig || !eglContext)
    {
        glusLogPrint(GLUS_LOG_ERROR, "No eglDisplay, eglConfig or eglContext passed");

        return EGL_FALSE;
    }

    // Get Display
    display = eglGetDisplay((EGLNativeDisplayType) eglNativeDisplayType);
    if (display == EGL_NO_DISPLAY)
    {
        glusLogPrint(GLUS_LOG_ERROR, "Could not get EGL display");

        return EGL_FALSE;
    }

    // Initialize EGL
    if (!eglInitialize(display, &majorVersion, &minorVersion))
    {
        glusLogPrint(GLUS_LOG_ERROR, "Could not initialize EGL");

        glusEGLTerminate(display, 0, 0);

        return EGL_FALSE;
    }

    glusLogPrint(GLUS_LOG_INFO, "EGL version: %d.%d", majorVersion, minorVersion);

    // Choose config
    if (!eglChooseConfig(display, attribList, &config, 1, &numConfigs))
    {
        glusLogPrint(GLUS_LOG_ERROR, "Could not choose EGL configuration");

        glusEGLTerminate(display, 0, 0);

        return EGL_FALSE;
    }

    if (numConfigs == 0)
    {
        glusLogPrint(GLUS_LOG_ERROR, "Could no EGL configuration returned");

        glusEGLTerminate(display, 0, 0);

        return EGL_FALSE;
    }

    contextAttribs[1] = eglContextClientVersion;

    // Create a GL ES context
    context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
    if (context == EGL_NO_CONTEXT)
    {
        glusLogPrint(GLUS_LOG_ERROR, "Could not create EGL context. EGL context client version: %d", eglContextClientVersion);

        glusEGLTerminate(eglDisplay, 0, 0);

        return EGL_FALSE;
    }

    glusLogPrint(GLUS_LOG_INFO, "EGL context client version: %d", eglContextClientVersion);

    *eglDisplay = display;
    *eglConfig = config;
    *eglContext = context;

    return EGL_TRUE;
}
Пример #18
0
GLUSboolean GLUSAPIENTRY glusCreateProgramFromSource(GLUSshaderprogram* shaderProgram, const GLUSchar** vertexSource, const GLUSchar** controlSource, const GLUSchar** evaluationSource, const GLUSchar** geometrySource, const GLUSchar** fragmentSource)
{
    GLUSint compiled;

    GLUSint logLength, charsWritten;

    char* log;

    if (!shaderProgram || !vertexSource || !fragmentSource)
    {
        return GLUS_FALSE;
    }

    shaderProgram->program = 0;
    shaderProgram->compute = 0;
    shaderProgram->vertex = 0;
    shaderProgram->control = 0;
    shaderProgram->evaluation = 0;
    shaderProgram->geometry = 0;
    shaderProgram->fragment = 0;

    shaderProgram->vertex = glCreateShader(GLUS_VERTEX_SHADER);

    glShaderSource(shaderProgram->vertex, 1, (const char**) vertexSource, 0);

    glCompileShader(shaderProgram->vertex);

    glGetShaderiv(shaderProgram->vertex, GL_COMPILE_STATUS, &compiled);

    if (!compiled)
    {
        glGetShaderiv(shaderProgram->vertex, GL_INFO_LOG_LENGTH, &logLength);

        log = (char*) malloc((size_t)logLength);

        if (!log)
        {
            return GLUS_FALSE;
        }

        glGetShaderInfoLog(shaderProgram->vertex, logLength, &charsWritten, log);

        glusLogPrint(GLUS_LOG_ERROR, "Vertex shader compile error:");
        glusLogPrint(GLUS_LOG_ERROR, "%s", log);

        free(log);

        shaderProgram->vertex = 0;

        return GLUS_FALSE;
    }

    if (controlSource)
    {
        shaderProgram->control = glCreateShader(GLUS_TESS_CONTROL_SHADER);

        glShaderSource(shaderProgram->control, 1, (const char**) controlSource, 0);

        glCompileShader(shaderProgram->control);

        glGetShaderiv(shaderProgram->control, GL_COMPILE_STATUS, &compiled);

        if (!compiled)
        {
            glGetShaderiv(shaderProgram->control, GL_INFO_LOG_LENGTH, &logLength);

            log = (char*) malloc((size_t)logLength);

            if (!log)
            {
                glusDestroyProgram(shaderProgram);

                return GLUS_FALSE;
            }

            glGetShaderInfoLog(shaderProgram->control, logLength, &charsWritten, log);

            glusLogPrint(GLUS_LOG_ERROR, "Control shader compile error:");
            glusLogPrint(GLUS_LOG_ERROR, "%s", log);

            free(log);

            shaderProgram->control = 0;

            glusDestroyProgram(shaderProgram);

            return GLUS_FALSE;
        }
    }

    if (evaluationSource)
    {
        shaderProgram->evaluation = glCreateShader(GLUS_TESS_EVALUATION_SHADER);

        glShaderSource(shaderProgram->evaluation, 1, (const char**) evaluationSource, 0);

        glCompileShader(shaderProgram->evaluation);

        glGetShaderiv(shaderProgram->evaluation, GL_COMPILE_STATUS, &compiled);

        if (!compiled)
        {
            glGetShaderiv(shaderProgram->evaluation, GL_INFO_LOG_LENGTH, &logLength);

            log = (char*) malloc((size_t)logLength);

            if (!log)
            {
                glusDestroyProgram(shaderProgram);

                return GLUS_FALSE;
            }

            glGetShaderInfoLog(shaderProgram->evaluation, logLength, &charsWritten, log);

            glusLogPrint(GLUS_LOG_ERROR, "Evaluation shader compile error:");
            glusLogPrint(GLUS_LOG_ERROR, "%s", log);

            free(log);

            shaderProgram->evaluation = 0;

            glusDestroyProgram(shaderProgram);

            return GLUS_FALSE;
        }
    }

    if (geometrySource)
    {
        shaderProgram->geometry = glCreateShader(GLUS_GEOMETRY_SHADER);

        glShaderSource(shaderProgram->geometry, 1, (const char**) geometrySource, 0);

        glCompileShader(shaderProgram->geometry);

        glGetShaderiv(shaderProgram->geometry, GL_COMPILE_STATUS, &compiled);

        if (!compiled)
        {
            glGetShaderiv(shaderProgram->geometry, GL_INFO_LOG_LENGTH, &logLength);

            log = (char*) malloc((size_t)logLength);

            if (!log)
            {
                glusDestroyProgram(shaderProgram);

                return GLUS_FALSE;
            }

            glGetShaderInfoLog(shaderProgram->geometry, logLength, &charsWritten, log);

            glusLogPrint(GLUS_LOG_ERROR, "Geometry shader compile error:");
            glusLogPrint(GLUS_LOG_ERROR, "%s", log);

            free(log);

            shaderProgram->geometry = 0;

            glusDestroyProgram(shaderProgram);

            return GLUS_FALSE;
        }
    }

    shaderProgram->fragment = glCreateShader(GLUS_FRAGMENT_SHADER);

    glShaderSource(shaderProgram->fragment, 1, (const char**) fragmentSource, 0);

    glCompileShader(shaderProgram->fragment);

    glGetShaderiv(shaderProgram->fragment, GL_COMPILE_STATUS, &compiled);

    if (!compiled)
    {
        glGetShaderiv(shaderProgram->fragment, GL_INFO_LOG_LENGTH, &logLength);

        log = (char*) malloc((size_t)logLength);

        if (!log)
        {
            glusDestroyProgram(shaderProgram);

            return GLUS_FALSE;
        }

        glGetShaderInfoLog(shaderProgram->fragment, logLength, &charsWritten, log);

        glusLogPrint(GLUS_LOG_ERROR, "Fragment shader compile error:");
        glusLogPrint(GLUS_LOG_ERROR, "%s", log);

        free(log);

        shaderProgram->fragment = 0;

        glusDestroyProgram(shaderProgram);

        return GLUS_FALSE;
    }

    shaderProgram->program = glCreateProgram();

    glAttachShader(shaderProgram->program, shaderProgram->vertex);

    if (shaderProgram->control)
    {
        glAttachShader(shaderProgram->program, shaderProgram->control);
    }

    if (shaderProgram->evaluation)
    {
        glAttachShader(shaderProgram->program, shaderProgram->evaluation);
    }

    if (shaderProgram->geometry)
    {
        glAttachShader(shaderProgram->program, shaderProgram->geometry);
    }

    glAttachShader(shaderProgram->program, shaderProgram->fragment);

    return GLUS_TRUE;
}
Пример #19
0
GLUSboolean GLUSAPIENTRY glusCreateWindow(const char* title, const GLUSint width, const GLUSint height, const GLUSint depthBits, const GLUSint stencilBits, const GLUSboolean fullscreen)
{
    GLUSenum err;

	if (g_windowCreated)
	{
    	glusLogPrint(GLUS_LOG_ERROR, "Window already exists");

        return GLUS_FALSE;
	}

    if (!glfwInit())
    {
    	glusLogPrint(GLUS_LOG_ERROR, "GLFW could not be initialized");

        return GLUS_FALSE;
    }

    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, g_major);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, g_minor);
    glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, g_flags & GLUS_FORWARD_COMPATIBLE_BIT);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, (g_flags & GLUS_FORWARD_COMPATIBLE_BIT) ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE);
    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, g_numberSamples);
    glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, g_noResize);

    // If we do not call this function in advance, glfwOpenWindow crashes in Debug under Windows
    glfwSetWindowTitle("");
    if (!glfwOpenWindow(width, height, 8, 8, 8, 8, depthBits, stencilBits, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW))
    {
    	glfwTerminate();

    	glusLogPrint(GLUS_LOG_ERROR, "GLFW window could not be opened");

        return GLUS_FALSE;
    }
    glfwSetWindowTitle(title);

    glewExperimental = GLUS_TRUE;

    err = glewInit();

    if (GLUS_OK != err)
    {
        glusDestroyWindow();

    	glusLogPrint(GLUS_LOG_ERROR, "GLEW could not be initialized: %x", err);

        return GLUS_FALSE;
    }

    if (!glusIsSupported(g_major, g_minor))
    {
        glusDestroyWindow();

        glusLogPrint(GLUS_LOG_ERROR, "OpenGL %u.%u not supported", g_major, g_minor);

        return GLUS_FALSE;
    }

    glfwSetWindowSizeCallback(glusInternalReshape);
    glfwSetWindowCloseCallback(glusInternalClose);
    glfwSetKeyCallback(glusInternalKey);
    glfwSetMouseButtonCallback(glusInternalMouse);
    glfwSetMouseWheelCallback(glusInternalMouseWheel);
    glfwSetMousePosCallback(glusInternalMouseMove);

    glfwGetWindowSize(&g_width, &g_height);

    g_windowCreated = GLUS_TRUE;

    return GLUS_TRUE; // Success
}
GLUSboolean GLUSAPIENTRY glusCreateProgramFromSource(GLUSshaderprogram* shaderProgram, const GLUSchar** vertexSource, const GLUSchar** fragmentSource)
{
    GLUSint compiled;

    GLUSint logLength, charsWritten;

    char* log;

    if (!shaderProgram || !vertexSource || !fragmentSource)
    {
        return GLUS_FALSE;
    }

    shaderProgram->program = 0;
    shaderProgram->compute = 0;
    shaderProgram->vertex = 0;
    shaderProgram->fragment = 0;

    shaderProgram->vertex = glCreateShader(GLUS_VERTEX_SHADER);

    glShaderSource(shaderProgram->vertex, 1, (const char**) vertexSource, 0);

    glCompileShader(shaderProgram->vertex);

    glGetShaderiv(shaderProgram->vertex, GL_COMPILE_STATUS, &compiled);

    if (!compiled)
    {
        glGetShaderiv(shaderProgram->vertex, GL_INFO_LOG_LENGTH, &logLength);

        log = (char*) malloc((size_t)logLength);

        if (!log)
        {
            return GLUS_FALSE;
        }

        glGetShaderInfoLog(shaderProgram->vertex, logLength, &charsWritten, log);

        glusLogPrint(GLUS_LOG_ERROR, "Vertex shader compile error:");
        glusLogPrint(GLUS_LOG_ERROR, "%s", log);

        free(log);

        shaderProgram->vertex = 0;

        return GLUS_FALSE;
    }

    shaderProgram->fragment = glCreateShader(GLUS_FRAGMENT_SHADER);

    glShaderSource(shaderProgram->fragment, 1, (const char**) fragmentSource, 0);

    glCompileShader(shaderProgram->fragment);

    glGetShaderiv(shaderProgram->fragment, GL_COMPILE_STATUS, &compiled);

    if (!compiled)
    {
        glGetShaderiv(shaderProgram->fragment, GL_INFO_LOG_LENGTH, &logLength);

        log = (char*) malloc((size_t)logLength);

        if (!log)
        {
            glusDestroyProgram(shaderProgram);

            return GLUS_FALSE;
        }

        glGetShaderInfoLog(shaderProgram->fragment, logLength, &charsWritten, log);

        glusLogPrint(GLUS_LOG_ERROR, "Fragment shader compile error:");
        glusLogPrint(GLUS_LOG_ERROR, "%s", log);

        free(log);

        shaderProgram->fragment = 0;

        glusDestroyProgram(shaderProgram);

        return GLUS_FALSE;
    }

    shaderProgram->program = glCreateProgram();

    glAttachShader(shaderProgram->program, shaderProgram->vertex);

    glAttachShader(shaderProgram->program, shaderProgram->fragment);

    return GLUS_TRUE;
}
Пример #21
0
EGLNativeWindowType _glusCreateNativeWindowType(const char* title, const GLUSint width, const GLUSint height, const GLUSboolean fullscreen, const GLUSboolean noResize)
{
	const SDL_VideoInfo* videoInfo;

	//

	DISPMANX_UPDATE_HANDLE_T dispmanUpdate;
	DISPMANX_ELEMENT_HANDLE_T dispmanElement;
	VC_RECT_T dstRect;
	VC_RECT_T srcRect;
	VC_DISPMANX_ALPHA_T dispmanAlpha;
	int32_t success;
	int32_t windowWidth;
	int32_t windowHeight;

	glusLogPrint(GLUS_LOG_INFO, "Parameters 'title' and 'noResize' are not used");

	// Initialize graphics system

	bcm_host_init();

	// Set fullscreen, if wanted

	if (fullscreen)
	{
		const uint32_t MAX_SUPPORTED_MODES = 128;
		HDMI_RES_GROUP_T group = HDMI_RES_GROUP_DMT;
		TV_SUPPORTED_MODE_NEW_T supportedModes[MAX_SUPPORTED_MODES];
		int32_t i, numberSupportedModes;

		numberSupportedModes = vc_tv_hdmi_get_supported_modes_new(group, supportedModes, MAX_SUPPORTED_MODES, 0, 0);

		for (i = 0; i < numberSupportedModes; i++)
		{
			if (supportedModes[i].width == (uint32_t)width && supportedModes[i].height == (uint32_t)height && supportedModes[i].frame_rate >= 60)
			{
				break;
			}
		}

		if (i == numberSupportedModes)
		{
			glusLogPrint(GLUS_LOG_ERROR, "No matching display resolution found: ", width, height);

			return EGL_NO_SURFACE ;
		}

		vc_tv_register_callback(resizeDone, 0);

		if (vc_tv_hdmi_power_on_explicit_new(group, supportedModes[i].group, supportedModes[i].code) != 0)
		{
			vc_tv_unregister_callback(resizeDone);

			glusLogPrint(GLUS_LOG_ERROR, "Could not switch to full screen: ", width, height);

			return EGL_NO_SURFACE ;
		}

		waitResizeDone();

		vc_tv_unregister_callback(resizeDone);

		windowWidth = width;
		windowHeight = height;

		_fullscreen = GLUS_TRUE;
	}
	else
	{
		windowWidth = width;
		windowHeight = height;
	}

	//

	_nativeDisplay = vc_dispmanx_display_open(0 /* LCD */);

	if (!_nativeDisplay)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not open display");

		return EGL_NO_SURFACE ;
	}

	//

	if (SDL_Init(SDL_INIT_VIDEO) != 0)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not initialize SDL");

		return EGL_NO_SURFACE ;
	}

	videoInfo = SDL_GetVideoInfo();

	if (!videoInfo)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not get video info for SDL");

		return EGL_NO_SURFACE ;
	}

	if (!SDL_SetVideoMode(videoInfo->current_w, videoInfo->current_h, videoInfo->vfmt->BitsPerPixel, SDL_HWSURFACE))
	{
		glusLogPrint(GLUS_LOG_ERROR, "Set video mode for SDL failed");

		return EGL_NO_SURFACE ;
	}

	SDL_ShowCursor(SDL_DISABLE);

	//

	dstRect.x = 0;
	dstRect.y = 0;
	dstRect.width = windowWidth;
	dstRect.height = windowHeight;

	srcRect.x = 0;
	srcRect.y = 0;
	srcRect.width = windowWidth << 16;
	srcRect.height = windowHeight << 16;

	dispmanAlpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
	dispmanAlpha.mask = 0xFFFFFFFF;
	dispmanAlpha.opacity = 255;

	dispmanUpdate = vc_dispmanx_update_start(0);

	dispmanElement = vc_dispmanx_element_add(dispmanUpdate, _nativeDisplay, 0 /*layer*/, &dstRect, 0 /*src*/, &srcRect, DISPMANX_PROTECTION_NONE, &dispmanAlpha, 0/*clamp*/, 0/*transform*/);

	success = vc_dispmanx_update_submit_sync(dispmanUpdate);

	if (!dispmanElement || success < 0)
	{
		glusLogPrint(GLUS_LOG_ERROR, "Could not add element");

		return EGL_NO_SURFACE ;
	}

	_width = windowWidth;
	_height = windowHeight;

	_nativeWindow.element = dispmanElement;
	_nativeWindow.width = windowWidth;
	_nativeWindow.height = windowHeight;

	_nativeWindowCreated = GLUS_TRUE;

	return (EGLNativeWindowType)&_nativeWindow;
}