1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00
occt/src/OpenGl/OpenGl_ShaderObject.cxx
abv d5f74e42d6 0024624: Lost word in license statement in source files
License statement text corrected; compiler warnings caused by Bison 2.41 disabled for MSVC; a few other compiler warnings on 54-bit Windows eliminated by appropriate type cast
Wrong license statements corrected in several files.
Copyright and license statements added in XSD and GLSL files.
Copyright year updated in some files.
Obsolete documentation files removed from DrawResources.
2014-02-20 16:15:17 +04:00

145 lines
4.7 KiB
C++
Executable File

// Created on: 2013-09-19
// Created by: Denis BOGOLEPOV
// Copyright (c) 2013-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Graphic3d_ShaderObject.hxx>
#include <OpenGl_Context.hxx>
#include <OpenGl_ShaderObject.hxx>
#include <OSD_Path.hxx>
#include <Standard_Assert.hxx>
#include <TCollection_AsciiString.hxx>
IMPLEMENT_STANDARD_HANDLE (OpenGl_ShaderObject, OpenGl_Resource)
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_ShaderObject, OpenGl_Resource)
// =======================================================================
// function : OpenGl_ShaderObject
// purpose : Creates uninitialized shader object
// =======================================================================
OpenGl_ShaderObject::OpenGl_ShaderObject (GLenum theType)
: myType (theType),
myShaderID (NO_SHADER)
{
//
}
// =======================================================================
// function : ~OpenGl_ShaderObject
// purpose : Releases resources of shader object
// =======================================================================
OpenGl_ShaderObject::~OpenGl_ShaderObject()
{
Release (NULL);
}
// =======================================================================
// function : LoadSource
// purpose : Loads shader source code
// =======================================================================
Standard_Boolean OpenGl_ShaderObject::LoadSource (const Handle(OpenGl_Context)& theCtx,
const TCollection_AsciiString& theSource)
{
if (myShaderID == NO_SHADER)
{
return Standard_False;
}
const GLchar* aLines = theSource.ToCString();
theCtx->core20->glShaderSource (myShaderID, 1, &aLines, NULL);
return Standard_True;
}
// =======================================================================
// function : Compile
// purpose : Compiles the shader object
// =======================================================================
Standard_Boolean OpenGl_ShaderObject::Compile (const Handle(OpenGl_Context)& theCtx)
{
if (myShaderID == NO_SHADER)
{
return Standard_False;
}
// Try to compile shader
theCtx->core20->glCompileShader (myShaderID);
// Check compile status
GLint aStatus = GL_FALSE;
theCtx->core20->glGetShaderiv (myShaderID, GL_COMPILE_STATUS, &aStatus);
return aStatus != GL_FALSE;
}
// =======================================================================
// function : FetchInfoLog
// purpose : Fetches information log of the last compile operation
// =======================================================================
Standard_Boolean OpenGl_ShaderObject::FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
TCollection_AsciiString& theLog)
{
if (myShaderID == NO_SHADER)
{
return Standard_False;
}
// Load information log of the compiler
GLint aLength = 0;
theCtx->core20->glGetShaderiv (myShaderID, GL_INFO_LOG_LENGTH, &aLength);
if (aLength > 0)
{
GLchar* aLog = (GLchar*) alloca (aLength);
memset (aLog, 0, aLength);
theCtx->core20->glGetShaderInfoLog (myShaderID, aLength, NULL, aLog);
theLog = aLog;
}
return Standard_True;
}
// =======================================================================
// function : Create
// purpose : Creates new empty shader object of specified type
// =======================================================================
Standard_Boolean OpenGl_ShaderObject::Create (const Handle(OpenGl_Context)& theCtx)
{
if (myShaderID == NO_SHADER
&& theCtx->core20 != NULL)
{
myShaderID = theCtx->core20->glCreateShader (myType);
}
return myShaderID != NO_SHADER;
}
// =======================================================================
// function : Release
// purpose : Destroys shader object
// =======================================================================
void OpenGl_ShaderObject::Release (const OpenGl_Context* theCtx)
{
if (myShaderID == NO_SHADER)
{
return;
}
Standard_ASSERT_RETURN (theCtx != NULL,
"OpenGl_ShaderObject destroyed without GL context! Possible GPU memory leakage...",);
if (theCtx->core20 != NULL
&& theCtx->IsValid())
{
theCtx->core20->glDeleteShader (myShaderID);
}
myShaderID = NO_SHADER;
}