LCOV - code coverage report
Current view: top level - slideshow/source/engine/OGLTrans/generic - OGLTrans_Shaders.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 45 0.0 %
Date: 2014-04-14 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5             :  *
       6             :  * Copyright 2008 by Sun Microsystems, Inc.
       7             :  *
       8             :  * OpenOffice.org - a multi-platform office productivity suite
       9             :  *
      10             :  * This file is part of OpenOffice.org.
      11             :  *
      12             :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13             :  * it under the terms of the GNU Lesser General Public License version 3
      14             :  * only, as published by the Free Software Foundation.
      15             :  *
      16             :  * OpenOffice.org is distributed in the hope that it will be useful,
      17             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :  * GNU Lesser General Public License version 3 for more details
      20             :  * (a copy is included in the LICENSE file that accompanied this code).
      21             :  *
      22             :  * You should have received a copy of the GNU Lesser General Public License
      23             :  * version 3 along with OpenOffice.org.  If not, see
      24             :  * <http://www.openoffice.org/license.html>
      25             :  * for a copy of the LGPLv3 License.
      26             :  *
      27             :  * This file incorporates work covered by the following license notice:
      28             :  *
      29             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      30             :  *   contributor license agreements. See the NOTICE file distributed
      31             :  *   with this work for additional information regarding copyright
      32             :  *   ownership. The ASF licenses this file to you under the Apache
      33             :  *   License, Version 2.0 (the "License"); you may not use this file
      34             :  *   except in compliance with the License. You may obtain a copy of
      35             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      36             :  ************************************************************************/
      37             : 
      38             : #include <config_lgpl.h>
      39             : 
      40             : #include <osl/diagnose.hxx>
      41             : 
      42             : #include "OGLTrans_Shaders.hxx"
      43             : 
      44             : #ifdef _WIN32
      45             : 
      46             : #elif defined(MACOSX)
      47             : 
      48             : #else // UNX == X11
      49             : 
      50             : namespace unx
      51             : {
      52             : #define GLX_GLXEXT_PROTOTYPES 1
      53             : #include <GL/glx.h>
      54             : #include <GL/glxext.h>
      55             : }
      56             : 
      57             : #endif
      58             : 
      59             : bool OGLShaders::cbInitialized = false;
      60             : 
      61             : #ifdef GL_VERSION_2_0
      62             : 
      63             : PFNGLACTIVETEXTUREPROC OGLShaders::glActiveTexture = NULL;
      64             : PFNGLCREATESHADERPROC OGLShaders::glCreateShader = NULL;
      65             : PFNGLSHADERSOURCEPROC OGLShaders::glShaderSource = NULL;
      66             : PFNGLCOMPILESHADERPROC OGLShaders::glCompileShader = NULL;
      67             : PFNGLGETSHADERIVPROC OGLShaders::glGetShaderiv = NULL;
      68             : PFNGLGETSHADERINFOLOGPROC OGLShaders::glGetShaderInfoLog = NULL;
      69             : PFNGLDELETESHADERPROC OGLShaders::glDeleteShader = NULL;
      70             : PFNGLCREATEPROGRAMPROC OGLShaders::glCreateProgram = NULL;
      71             : PFNGLATTACHSHADERPROC OGLShaders::glAttachShader = NULL;
      72             : PFNGLLINKPROGRAMPROC OGLShaders::glLinkProgram = NULL;
      73             : PFNGLGETPROGRAMIVPROC OGLShaders::glGetProgramiv = NULL;
      74             : PFNGLGETPROGRAMINFOLOGPROC OGLShaders::glGetProgramInfoLog = NULL;
      75             : PFNGLUSEPROGRAMPROC OGLShaders::glUseProgram = NULL;
      76             : PFNGLDELETEPROGRAMPROC OGLShaders::glDeleteProgram = NULL;
      77             : PFNGLGETUNIFORMLOCATIONPROC OGLShaders::glGetUniformLocation = NULL;
      78             : PFNGLUNIFORM1IPROC OGLShaders::glUniform1i = NULL;
      79             : PFNGLUNIFORM1FPROC OGLShaders::glUniform1f = NULL;
      80             : #endif
      81             : 
      82           0 : bool OGLShaders::Initialize()
      83             : {
      84             : #ifdef GL_VERSION_2_0
      85           0 :     if( !cbInitialized ) {
      86             : #ifdef _WIN32
      87             :         glActiveTexture = (PFNGLACTIVETEXTUREPROC) wglGetProcAddress( "glActiveTexture" );
      88             :         glCreateShader = (PFNGLCREATESHADERPROC) wglGetProcAddress( "glCreateShader" );
      89             :         glShaderSource = (PFNGLSHADERSOURCEPROC) wglGetProcAddress( "glShaderSource" );
      90             :         glCompileShader = (PFNGLCOMPILESHADERPROC) wglGetProcAddress( "glCompileShader" );
      91             :         glGetShaderiv = (PFNGLGETSHADERIVPROC) wglGetProcAddress( "glGetShaderiv" );
      92             :         glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) wglGetProcAddress( "glGetShaderInfoLog" );
      93             :         glDeleteShader = (PFNGLDELETESHADERPROC) wglGetProcAddress( "glDeleteShader" );
      94             :         glCreateProgram = (PFNGLCREATEPROGRAMPROC) wglGetProcAddress( "glCreateProgram" );
      95             :         glAttachShader = (PFNGLATTACHSHADERPROC) wglGetProcAddress( "glAttachShader" );
      96             :         glLinkProgram = (PFNGLLINKPROGRAMPROC) wglGetProcAddress( "glLinkProgram" );
      97             :         glGetProgramiv = (PFNGLGETPROGRAMIVPROC) wglGetProcAddress( "glGetProgramiv" );
      98             :         glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) wglGetProcAddress( "glGetProgramInfoLog" );
      99             :         glUseProgram = (PFNGLUSEPROGRAMPROC) wglGetProcAddress( "glUseProgram" );
     100             :         glDeleteProgram = (PFNGLDELETEPROGRAMPROC) wglGetProcAddress( "glDeleteProgram" );
     101             :         glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) wglGetProcAddress( "glGetUniformLocation" );
     102             :         glUniform1i = (PFNGLUNIFORM1IPROC) wglGetProcAddress( "glUniform1i" );
     103             :         glUniform1f = (PFNGLUNIFORM1FPROC) wglGetProcAddress( "glUniform1f" );
     104             :         cbInitialized = true;
     105             : #elif defined(MACOSX)
     106             : #else
     107           0 :         glActiveTexture = (PFNGLACTIVETEXTUREPROC) unx::glXGetProcAddress( (unsigned char *) "glActiveTexture" );
     108           0 :         glCreateShader = (PFNGLCREATESHADERPROC) unx::glXGetProcAddress( (unsigned char *) "glCreateShader" );
     109           0 :         glShaderSource = (PFNGLSHADERSOURCEPROC) unx::glXGetProcAddress( (unsigned char *) "glShaderSource" );
     110           0 :         glCompileShader = (PFNGLCOMPILESHADERPROC) unx::glXGetProcAddress( (unsigned char *) "glCompileShader" );
     111           0 :         glGetShaderiv = (PFNGLGETSHADERIVPROC) unx::glXGetProcAddress( (unsigned char *) "glGetShaderiv" );
     112           0 :         glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) unx::glXGetProcAddress( (unsigned char *) "glGetShaderInfoLog" );
     113           0 :         glDeleteShader = (PFNGLDELETESHADERPROC) unx::glXGetProcAddress( (unsigned char *) "glDeleteShader" );
     114           0 :         glCreateProgram = (PFNGLCREATEPROGRAMPROC) unx::glXGetProcAddress( (unsigned char *) "glCreateProgram" );
     115           0 :         glAttachShader = (PFNGLATTACHSHADERPROC) unx::glXGetProcAddress( (unsigned char *) "glAttachShader" );
     116           0 :         glLinkProgram = (PFNGLLINKPROGRAMPROC) unx::glXGetProcAddress( (unsigned char *) "glLinkProgram" );
     117           0 :         glGetProgramiv = (PFNGLGETPROGRAMIVPROC) unx::glXGetProcAddress( (unsigned char *) "glGetProgramiv" );
     118           0 :         glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) unx::glXGetProcAddress( (unsigned char *) "glGetProgramInfoLog" );
     119           0 :         glUseProgram = (PFNGLUSEPROGRAMPROC) unx::glXGetProcAddress( (unsigned char *) "glUseProgram" );
     120           0 :         glDeleteProgram = (PFNGLDELETEPROGRAMPROC) unx::glXGetProcAddress( (unsigned char *) "glDeleteProgram" );
     121           0 :         glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC) unx::glXGetProcAddress( (unsigned char *) "glGetUniformLocation" );
     122           0 :         glUniform1i = (PFNGLUNIFORM1IPROC) unx::glXGetProcAddress( (unsigned char *) "glUniform1i" );
     123           0 :         glUniform1f = (PFNGLUNIFORM1FPROC) unx::glXGetProcAddress( (unsigned char *) "glUniform1f" );
     124           0 :         cbInitialized = true;
     125             : #endif
     126             :     }
     127             : 
     128           0 :     return glCreateShader != NULL;
     129             : #else
     130             :     return false;
     131             : #endif
     132             : }
     133             : 
     134           0 : GLuint OGLShaders::LinkProgram( const char *vertexShader, const char *fragmentShader )
     135             : {
     136             : #ifdef GL_VERSION_2_0
     137           0 :     if( !Initialize() )
     138           0 :         return 0;
     139             : 
     140             :     GLhandleARB vertexObject, fragmentObject, programObject;
     141             :     GLint vertexCompiled, fragmentCompiled, programLinked;
     142             :     char log[1024];
     143             : 
     144           0 :     vertexObject = glCreateShader( GL_VERTEX_SHADER );
     145           0 :     fragmentObject = glCreateShader( GL_FRAGMENT_SHADER );
     146             :     SAL_INFO("slideshow.opengl", "checkpoint 1: shaders created (" << (glGetError() == GL_NO_ERROR) << ") vertex: " << vertexObject << " fragment: " << fragmentObject);
     147             : 
     148             : 
     149           0 :     glShaderSource( vertexObject, 1, &vertexShader, NULL );
     150           0 :     glShaderSource( fragmentObject, 1, &fragmentShader, NULL );
     151             : 
     152           0 :     glCompileShader( vertexObject );
     153           0 :     glGetShaderInfoLog( vertexObject, sizeof( log ), NULL, log );
     154             :     SAL_INFO("slideshow.opengl", "vertex compile log: " << log);
     155           0 :     glGetShaderiv( vertexObject, GL_COMPILE_STATUS, &vertexCompiled );
     156           0 :     glCompileShader( fragmentObject );
     157           0 :     glGetShaderInfoLog( fragmentObject, sizeof( log ), NULL, log );
     158             :     SAL_INFO("slideshow.opengl", "fragment compile log: " << log);
     159           0 :     glGetShaderiv( fragmentObject, GL_COMPILE_STATUS, &fragmentCompiled );
     160             : 
     161           0 :     if( !vertexCompiled || !fragmentCompiled )
     162           0 :         return 0;
     163             : 
     164             :     SAL_INFO("slideshow.opengl", "checkpoint 2: shaders compiled (" << (glGetError() == GL_NO_ERROR) << ')');
     165             : 
     166           0 :     programObject = glCreateProgram();
     167           0 :     glAttachShader( programObject, vertexObject );
     168           0 :     glAttachShader( programObject, fragmentObject );
     169             : 
     170           0 :     glLinkProgram( programObject );
     171           0 :     glGetProgramInfoLog( programObject, sizeof( log ), NULL, log );
     172             :     SAL_INFO("slideshow.opengl", "program link log: " << log);
     173           0 :     glGetProgramiv( programObject, GL_LINK_STATUS, &programLinked );
     174             : 
     175           0 :     if( !programLinked )
     176           0 :         return 0;
     177             : 
     178             :     SAL_INFO("slideshow.opengl", "checkpoint 3: program linked (" << (glGetError() == GL_NO_ERROR) << ')');
     179             : 
     180           0 :     return programObject;
     181             : #else
     182             :     return 0;
     183             : #endif
     184             : }
     185             : 
     186             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10