// Created by: Denis BOGOLEPOV
// Copyright (c) 2013 OPEN CASCADE SAS
//
-// The content of this file is subject to the Open CASCADE Technology Public
-// License Version 6.5 (the "License"). You may not use the content of this file
-// except in compliance with the License. Please obtain a copy of the License
-// at http://www.opencascade.org and read it completely before using this file.
+// This file is part of Open CASCADE Technology software library.
//
-// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
-// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+// This library is free software; you can redistribute it and / or modify it
+// under the terms of the GNU Lesser General Public 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.
//
-// The Original Code and all software distributed under the License is
-// distributed on an "AS IS" basis, without warranty of any kind, and the
-// Initial Developer hereby disclaims all such warranties, including without
-// limitation, any warranties of merchantability, fitness for a particular
-// purpose or non-infringement. Please see the License for the specific terms
-// and conditions governing the rights and limitations under the License.
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
#ifdef HAVE_CONFIG_H
#include <config.h>
using namespace OpenGl_Raytrace;
//! Use this macro to output ray-tracing debug info
-// #define RAY_TRACE_PRINT_INFO
+//#define RAY_TRACE_PRINT_INFO
#ifdef RAY_TRACE_PRINT_INFO
#include <OSD_Timer.hxx>
if (myRaytraceEnvironment != NULL)
clReleaseMemObject (myRaytraceEnvironment);
- int aSizeX = 1;
- int aSizeY = 1;
+ Standard_Integer aSizeX = 1;
+ Standard_Integer aSizeY = 1;
if (!myView->TextureEnv().IsNull() && myView->SurfaceDetail() != Visual3d_TOD_NONE)
{
}
else
{
- for (int aPixel = 0; aPixel < aSizeX * aSizeY * 4; ++aPixel)
+ for (Standard_Integer aPixel = 0; aPixel < aSizeX * aSizeY * 4; ++aPixel)
aPixelData[aPixel] = 0.f;
}
const OpenGl_ArrayOfStructure& aStructArray = aPriorityList.ArrayOfStructures();
- for (int anIndex = 0; anIndex < aStructArray.Length(); ++anIndex)
+ for (Standard_Integer anIndex = 0; anIndex < aStructArray.Length(); ++anIndex)
{
OpenGl_SequenceOfStructure::Iterator aStructIt;
if (aTransform == NULL)
aTransform = new float[16];
- for (int i = 0; i < 4; ++i)
- for (int j = 0; j < 4; ++j)
+ for (Standard_Integer i = 0; i < 4; ++i)
+ for (Standard_Integer j = 0; j < 4; ++j)
{
aTransform[j * 4 + i] = aStructure->Transformation()->mat[i][j];
}
// function : CreateMaterial
// purpose : Creates ray-tracing material properties
// =======================================================================
-void CreateMaterial (const OPENGL_SURF_PROP& theProp, OpenGl_RaytraceMaterial& theMaterial)
+void CreateMaterial (const OPENGL_SURF_PROP& theProp,
+ OpenGl_RaytraceMaterial& theMaterial)
{
- theMaterial.Ambient = OpenGl_RTVec4f (theProp.ambcol.rgb[0] * theProp.amb,
- theProp.ambcol.rgb[1] * theProp.amb,
- theProp.ambcol.rgb[2] * theProp.amb,
- 1.f);
-
- theMaterial.Diffuse = OpenGl_RTVec4f (theProp.difcol.rgb[0] * theProp.diff,
- theProp.difcol.rgb[1] * theProp.diff,
- theProp.difcol.rgb[2] * theProp.diff,
- 1.f);
-
- theMaterial.Specular = OpenGl_RTVec4f (theProp.speccol.rgb[0] * theProp.spec,
- theProp.speccol.rgb[1] * theProp.spec,
- theProp.speccol.rgb[2] * theProp.spec,
+ const float* aSrcAmb = theProp.isphysic ? theProp.ambcol.rgb : theProp.matcol.rgb;
+ theMaterial.Ambient = OpenGl_RTVec4f (aSrcAmb[0] * theProp.amb,
+ aSrcAmb[1] * theProp.amb,
+ aSrcAmb[2] * theProp.amb,
+ 1.0f);
+
+ const float* aSrcDif = theProp.isphysic ? theProp.difcol.rgb : theProp.matcol.rgb;
+ theMaterial.Diffuse = OpenGl_RTVec4f (aSrcDif[0] * theProp.diff,
+ aSrcDif[1] * theProp.diff,
+ aSrcDif[2] * theProp.diff,
+ 1.0f);
+
+ const float aDefSpecCol[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ const float* aSrcSpe = theProp.isphysic ? theProp.speccol.rgb : aDefSpecCol;
+ theMaterial.Specular = OpenGl_RTVec4f (aSrcSpe[0] * theProp.spec,
+ aSrcSpe[1] * theProp.spec,
+ aSrcSpe[2] * theProp.spec,
theProp.shine);
- theMaterial.Emission = OpenGl_RTVec4f (theProp.emscol.rgb[0] * theProp.emsv,
- theProp.emscol.rgb[1] * theProp.emsv,
- theProp.emscol.rgb[2] * theProp.emsv,
- 1.f);
+ const float* aSrcEms = theProp.isphysic ? theProp.emscol.rgb : theProp.matcol.rgb;
+ theMaterial.Emission = OpenGl_RTVec4f (aSrcEms[0] * theProp.emsv,
+ aSrcEms[1] * theProp.emsv,
+ aSrcEms[2] * theProp.emsv,
+ 1.0f);
// Note: Here we use sub-linear transparency function
// to produce realistic-looking transparency effect
}
// Get structure material
- int aStructMatID = -1;
+ Standard_Integer aStructMatID = -1;
if (theStructure->AspectFace() != NULL)
{
- aStructMatID = static_cast<int> (myRaytraceSceneData.Materials.size());
+ aStructMatID = static_cast<Standard_Integer> (myRaytraceSceneData.Materials.size());
OpenGl_RaytraceMaterial aStructMaterial;
CreateMaterial (theStructure->AspectFace()->IntFront(), aStructMaterial);
while (anItg.More())
{
// Get group material
- int aGroupMatID = -1;
+ Standard_Integer aGroupMatID = -1;
if (anItg.Value()->AspectFace() != NULL)
{
- aGroupMatID = static_cast<int> (myRaytraceSceneData.Materials.size());
+ aGroupMatID = static_cast<Standard_Integer> (myRaytraceSceneData.Materials.size());
OpenGl_RaytraceMaterial aGroupMaterial;
CreateMaterial (anItg.Value()->AspectFace()->IntFront(), aGroupMaterial);
myRaytraceSceneData.Materials.push_back (aGroupMaterial);
}
- int aMatID = aGroupMatID < 0 ? aStructMatID : aGroupMatID;
+ Standard_Integer aMatID = aGroupMatID < 0 ? aStructMatID : aGroupMatID;
if (aStructMatID < 0 && aGroupMatID < 0)
{
- aMatID = static_cast<int> (myRaytraceSceneData.Materials.size());
+ aMatID = static_cast<Standard_Integer> (myRaytraceSceneData.Materials.size());
myRaytraceSceneData.Materials.push_back (OpenGl_RaytraceMaterial());
}
if (anAspect != NULL)
{
- aMatID = static_cast<int> (myRaytraceSceneData.Materials.size());
+ aMatID = static_cast<Standard_Integer> (myRaytraceSceneData.Materials.size());
OpenGl_RaytraceMaterial aMaterial;
CreateMaterial (anAspect->IntFront(), aMaterial);
{
float* aTransform = new float[16];
- for (int i = 0; i < 4; ++i)
- for (int j = 0; j < 4; ++j)
+ for (Standard_Integer i = 0; i < 4; ++i)
+ for (Standard_Integer j = 0; j < 4; ++j)
{
aTransform[j * 4 + i] =
anIts.Value()->Transformation()->mat[i][j];
// purpose : Adds OpenGL primitive array to ray-traced scene geometry
// =======================================================================
Standard_Boolean OpenGl_Workspace::AddRaytracePrimitiveArray (const CALL_DEF_PARRAY* theArray,
- int theMatID,
+ Standard_Integer theMatID,
const float* theTransform)
{
if (theArray->type != TelPolygonsArrayType &&
myRaytraceSceneData.Vertices.reserve (
myRaytraceSceneData.Vertices.size() + theArray->num_vertexs);
- const int aFirstVert = static_cast<int> (myRaytraceSceneData.Vertices.size());
+ const Standard_Integer aFirstVert = static_cast<Standard_Integer> (myRaytraceSceneData.Vertices.size());
- for (int aVert = 0; aVert < theArray->num_vertexs; ++aVert)
+ for (Standard_Integer aVert = 0; aVert < theArray->num_vertexs; ++aVert)
{
OpenGl_RTVec4f aVertex (theArray->vertices[aVert].xyz[0],
theArray->vertices[aVert].xyz[1],
myRaytraceSceneData.Normals.reserve (
myRaytraceSceneData.Normals.size() + theArray->num_vertexs);
- for (int aNorm = 0; aNorm < theArray->num_vertexs; ++aNorm)
+ for (Standard_Integer aNorm = 0; aNorm < theArray->num_vertexs; ++aNorm)
{
OpenGl_RTVec4f aNormal;
std::cout << "\tNumber of bounds = " << theArray->num_bounds << std::endl;
#endif
- int aVertOffset = 0;
+ Standard_Integer aVertOffset = 0;
- for (int aBound = 0; aBound < theArray->num_bounds; ++aBound)
+ for (Standard_Integer aBound = 0; aBound < theArray->num_bounds; ++aBound)
{
- const int aVertNum = theArray->bounds[aBound];
+ const Standard_Integer aVertNum = theArray->bounds[aBound];
#ifdef RAY_TRACE_PRINT_INFO
std::cout << "\tAdd indices from bound " << aBound << ": " <<
}
else
{
- const int aVertNum = theArray->num_edges > 0 ? theArray->num_edges : theArray->num_vertexs;
+ const Standard_Integer aVertNum = theArray->num_edges > 0 ? theArray->num_edges : theArray->num_vertexs;
#ifdef RAY_TRACE_PRINT_INFO
std::cout << "\tAdd indices: " << aVertNum << std::endl;
// purpose : Adds vertex indices to ray-traced scene geometry
// =======================================================================
Standard_Boolean OpenGl_Workspace::AddRaytraceVertexIndices (const CALL_DEF_PARRAY* theArray,
- int theFirstVert,
- int theVertOffset,
- int theVertNum,
- int theMatID)
+ Standard_Integer theFirstVert,
+ Standard_Integer theVertOffset,
+ Standard_Integer theVertNum,
+ Standard_Integer theMatID)
{
myRaytraceSceneData.Triangles.reserve (myRaytraceSceneData.Triangles.size() + theVertNum);
switch (theArray->type)
// purpose : Adds OpenGL triangle array to ray-traced scene geometry
// =======================================================================
Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleArray (const CALL_DEF_PARRAY* theArray,
- int theFirstVert,
- int theVertOffset,
- int theVertNum,
- int theMatID)
+ Standard_Integer theFirstVert,
+ Standard_Integer theVertOffset,
+ Standard_Integer theVertNum,
+ Standard_Integer theMatID)
{
if (theVertNum < 3)
return Standard_True;
if (theArray->num_edges > 0)
{
- for (int aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; aVert += 3)
+ for (Standard_Integer aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; aVert += 3)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + theArray->edges[aVert + 0],
theFirstVert + theArray->edges[aVert + 1],
}
else
{
- for (int aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; aVert += 3)
+ for (Standard_Integer aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; aVert += 3)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + aVert + 0,
theFirstVert + aVert + 1,
// purpose : Adds OpenGL triangle fan array to ray-traced scene geometry
// =======================================================================
Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleFanArray (const CALL_DEF_PARRAY* theArray,
- int theFirstVert,
- int theVertOffset,
- int theVertNum,
- int theMatID)
+ Standard_Integer theFirstVert,
+ Standard_Integer theVertOffset,
+ Standard_Integer theVertNum,
+ Standard_Integer theMatID)
{
if (theVertNum < 3)
return Standard_True;
if (theArray->num_edges > 0)
{
- for (int aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; ++aVert)
+ for (Standard_Integer aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; ++aVert)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + theArray->edges[theVertOffset],
theFirstVert + theArray->edges[aVert + 1],
}
else
{
- for (int aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; ++aVert)
+ for (Standard_Integer aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; ++aVert)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + theVertOffset,
theFirstVert + aVert + 1,
// purpose : Adds OpenGL triangle strip array to ray-traced scene geometry
// =======================================================================
Standard_Boolean OpenGl_Workspace::AddRaytraceTriangleStripArray (const CALL_DEF_PARRAY* theArray,
- int theFirstVert,
- int theVertOffset,
- int theVertNum,
- int theMatID)
+ Standard_Integer theFirstVert,
+ Standard_Integer theVertOffset,
+ Standard_Integer theVertNum,
+ Standard_Integer theMatID)
{
if (theVertNum < 3)
return Standard_True;
theFirstVert + theArray->edges[theVertOffset + 2],
theMatID));
- for (int aVert = theVertOffset + 1, aTriNum = 1; aVert < theVertOffset + theVertNum - 2; ++aVert, ++aTriNum)
+ for (Standard_Integer aVert = theVertOffset + 1, aTriNum = 1; aVert < theVertOffset + theVertNum - 2; ++aVert, ++aTriNum)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (
theFirstVert + theArray->edges[aVert + (aTriNum % 2) ? 1 : 0],
theFirstVert + theVertOffset + 2,
theMatID));
- for (int aVert = theVertOffset + 1, aTriNum = 1; aVert < theVertOffset + theVertNum - 2; ++aVert, ++aTriNum)
+ for (Standard_Integer aVert = theVertOffset + 1, aTriNum = 1; aVert < theVertOffset + theVertNum - 2; ++aVert, ++aTriNum)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + aVert + ( aTriNum % 2 ) ? 1 : 0,
theFirstVert + aVert + ( aTriNum % 2 ) ? 0 : 1,
// purpose : Adds OpenGL quad array to ray-traced scene geometry
// =======================================================================
Standard_Boolean OpenGl_Workspace::AddRaytraceQuadrangleArray (const CALL_DEF_PARRAY* theArray,
- int theFirstVert,
- int theVertOffset,
- int theVertNum,
- int theMatID)
+ Standard_Integer theFirstVert,
+ Standard_Integer theVertOffset,
+ Standard_Integer theVertNum,
+ Standard_Integer theMatID)
{
if (theVertNum < 4)
return Standard_True;
if (theArray->num_edges > 0)
{
- for (int aVert = theVertOffset; aVert < theVertOffset + theVertNum - 3; aVert += 4)
+ for (Standard_Integer aVert = theVertOffset; aVert < theVertOffset + theVertNum - 3; aVert += 4)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + theArray->edges[aVert + 0],
theFirstVert + theArray->edges[aVert + 1],
}
else
{
- for (int aVert = theVertOffset; aVert < theVertOffset + theVertNum - 3; aVert += 4)
+ for (Standard_Integer aVert = theVertOffset; aVert < theVertOffset + theVertNum - 3; aVert += 4)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + aVert + 0,
theFirstVert + aVert + 1,
// purpose : Adds OpenGL quad strip array to ray-traced scene geometry
// =======================================================================
Standard_Boolean OpenGl_Workspace::AddRaytraceQuadrangleStripArray (const CALL_DEF_PARRAY* theArray,
- int theFirstVert,
- int theVertOffset,
- int theVertNum,
- int theMatID)
+ Standard_Integer theFirstVert,
+ Standard_Integer theVertOffset,
+ Standard_Integer theVertNum,
+ Standard_Integer theMatID)
{
if (theVertNum < 4)
return Standard_True;
theFirstVert + theArray->edges[theVertOffset + 2],
theMatID));
- for (int aVert = theVertOffset + 2; aVert < theVertOffset + theVertNum - 3; aVert += 2)
+ for (Standard_Integer aVert = theVertOffset + 2; aVert < theVertOffset + theVertNum - 3; aVert += 2)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (
theFirstVert + theArray->edges[aVert + 0],
theFirstVert + 2,
theMatID));
- for (int aVert = theVertOffset + 2; aVert < theVertOffset + theVertNum - 3; aVert += 2)
+ for (Standard_Integer aVert = theVertOffset + 2; aVert < theVertOffset + theVertNum - 3; aVert += 2)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + aVert + 0,
theFirstVert + aVert + 1,
// purpose : Adds OpenGL polygon array to ray-traced scene geometry
// =======================================================================
Standard_Boolean OpenGl_Workspace::AddRaytracePolygonArray (const CALL_DEF_PARRAY* theArray,
- int theFirstVert,
- int theVertOffset,
- int theVertNum,
- int theMatID)
+ Standard_Integer theFirstVert,
+ Standard_Integer theVertOffset,
+ Standard_Integer theVertNum,
+ Standard_Integer theMatID)
{
if (theArray->num_vertexs < 3)
return Standard_True;
if (theArray->edges != NULL)
{
- for (int aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; ++aVert)
+ for (Standard_Integer aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; ++aVert)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + theArray->edges[theVertOffset],
theFirstVert + theArray->edges[aVert + 1],
}
else
{
- for (int aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; ++aVert)
+ for (Standard_Integer aVert = theVertOffset; aVert < theVertOffset + theVertNum - 2; ++aVert)
{
myRaytraceSceneData.Triangles.push_back (OpenGl_RTVec4i (theFirstVert + theVertOffset,
theFirstVert + aVert + 1,
{
myRaytraceSceneData.LightSources.clear();
- OpenGl_ListOfLight::Iterator anItl (myView->LightList());
-
- OpenGl_RTVec4f aAmbient (0.f, 0.f, 0.f, 0.f);
-
- for (; anItl.More(); anItl.Next())
+ OpenGl_RTVec4f anAmbient (0.0f, 0.0f, 0.0f, 0.0f);
+ for (OpenGl_ListOfLight::Iterator anItl (myView->LightList());
+ anItl.More(); anItl.Next())
{
- const OpenGl_Light &aLight = anItl.Value();
-
- if (aLight.type == TLightAmbient)
+ const OpenGl_Light& aLight = anItl.Value();
+ if (aLight.Type == Visual3d_TOLS_AMBIENT)
{
- aAmbient += OpenGl_RTVec4f (aLight.col.rgb[0],
- aLight.col.rgb[1],
- aLight.col.rgb[2],
- 0.f);
+ anAmbient += OpenGl_RTVec4f (aLight.Color.r(), aLight.Color.g(), aLight.Color.b(), 0.0f);
continue;
}
- OpenGl_RTVec4f aDiffuse (aLight.col.rgb[0],
- aLight.col.rgb[1],
- aLight.col.rgb[2],
- 1.f);
-
- OpenGl_RTVec4f aPosition (-aLight.dir[0],
- -aLight.dir[1],
- -aLight.dir[2],
- 0.f);
-
- if (aLight.type != TLightDirectional)
+ OpenGl_RTVec4f aDiffuse (aLight.Color.r(), aLight.Color.g(), aLight.Color.b(), 1.0f);
+ OpenGl_RTVec4f aPosition (-aLight.Direction.x(), -aLight.Direction.y(), -aLight.Direction.z(), 0.0f);
+ if (aLight.Type != Visual3d_TOLS_DIRECTIONAL)
{
- aPosition = OpenGl_RTVec4f (aLight.pos[0],
- aLight.pos[1],
- aLight.pos[2],
- 1.f);
+ aPosition = OpenGl_RTVec4f (aLight.Position.x(), aLight.Position.y(), aLight.Position.z(), 1.0f);
}
-
- if (aLight.HeadLight)
+ if (aLight.IsHeadlight)
{
aPosition = MatVecMult (theInvModelView, aPosition);
}
if (myRaytraceSceneData.LightSources.size() > 0)
{
- myRaytraceSceneData.LightSources.front().Ambient += aAmbient;
+ myRaytraceSceneData.LightSources.front().Ambient += anAmbient;
}
else
{
- myRaytraceSceneData.LightSources.push_back (OpenGl_RaytraceLight (OpenGl_RTVec4f (aAmbient.xyz(), -1.0f)));
+ myRaytraceSceneData.LightSources.push_back (OpenGl_RaytraceLight (OpenGl_RTVec4f (anAmbient.rgb(), -1.0f)));
}
cl_int anError = CL_SUCCESS;
clReleaseMemObject (myRaytraceOutputImage);
clReleaseMemObject (myRaytraceEnvironment);
- clReleaseMemObject (myRaytraceOutputImageSmooth);
+ clReleaseMemObject (myRaytraceOutputImageAA);
clReleaseMemObject (myRaytraceVertexBuffer);
clReleaseMemObject (myRaytraceNormalBuffer);
clReleaseContext (myComputeContext);
- if (glIsTexture (*myRaytraceOutputTexture))
- glDeleteTextures (2, myRaytraceOutputTexture);
+ if (!myGlContext.IsNull())
+ {
+ if (!myRaytraceOutputTexture.IsNull())
+ myGlContext->DelayedRelease (myRaytraceOutputTexture);
+ myRaytraceOutputTexture.Nullify();
+
+ if (!myRaytraceOutputTextureAA.IsNull())
+ myGlContext->DelayedRelease (myRaytraceOutputTextureAA);
+ myRaytraceOutputTextureAA.Nullify();
+ }
}
// =======================================================================
return Standard_False;
}
- bool toResize = true;
- GLint aSizeX = -1;
- GLint aSizeY = -1;
- if (*myRaytraceOutputTexture != 0)
+ if (!myRaytraceOutputTexture.IsNull())
{
- if (!myGlContext->IsGlGreaterEqual (2, 1))
- {
- return Standard_False;
- }
+ Standard_Boolean toResize = myRaytraceOutputTexture->SizeX() != theSizeX ||
+ myRaytraceOutputTexture->SizeY() != theSizeY;
- glBindTexture (GL_TEXTURE_RECTANGLE, *myRaytraceOutputTexture);
-
- glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_WIDTH, &aSizeX);
- glGetTexLevelParameteriv (GL_TEXTURE_RECTANGLE, 0, GL_TEXTURE_HEIGHT, &aSizeY);
+ if (!toResize)
+ return Standard_True;
- toResize = (aSizeX != theSizeX) || (aSizeY != theSizeY);
- if (toResize)
+ if (!myGlContext.IsNull())
{
- glDeleteTextures (2, myRaytraceOutputTexture);
+ if (!myRaytraceOutputTexture.IsNull())
+ myGlContext->DelayedRelease (myRaytraceOutputTexture);
+ if (!myRaytraceOutputTextureAA.IsNull())
+ myGlContext->DelayedRelease (myRaytraceOutputTextureAA);
}
}
- if (!toResize)
- {
- return Standard_True;
- }
-
- glGenTextures (2, myRaytraceOutputTexture);
- for (int aTexIter = 0; aTexIter < 2; ++aTexIter)
- {
- glBindTexture (GL_TEXTURE_RECTANGLE, myRaytraceOutputTexture[aTexIter]);
-
- glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_WRAP_R, GL_CLAMP);
+
+ myRaytraceOutputTexture = new OpenGl_Texture();
+
+ myRaytraceOutputTexture->Create (myGlContext);
+ myRaytraceOutputTexture->InitRectangle (myGlContext,
+ theSizeX, theSizeY, OpenGl_TextureFormat::Create<GLfloat, 4>());
+
+ myRaytraceOutputTextureAA = new OpenGl_Texture();
+
+ myRaytraceOutputTextureAA->Create (myGlContext);
+ myRaytraceOutputTextureAA->InitRectangle (myGlContext,
+ theSizeX, theSizeY, OpenGl_TextureFormat::Create<GLfloat, 4>());
- glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri (GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ if (myRaytraceOutputImage != NULL)
+ clReleaseMemObject (myRaytraceOutputImage);
- glTexImage2D (GL_TEXTURE_RECTANGLE, 0, GL_RGBA32F,
- theSizeX, theSizeY, 0,
- GL_RGBA, GL_FLOAT, NULL);
- }
+ if (myRaytraceOutputImageAA != NULL)
+ clReleaseMemObject (myRaytraceOutputImageAA);
cl_int anError = CL_SUCCESS;
- if (myRaytraceOutputImage != NULL)
- {
- clReleaseMemObject (myRaytraceOutputImage);
- }
- if (myRaytraceOutputImageSmooth != NULL)
- {
- clReleaseMemObject (myRaytraceOutputImageSmooth);
- }
+ myRaytraceOutputImage = clCreateFromGLTexture2D (myComputeContext,
+ CL_MEM_READ_WRITE, GL_TEXTURE_RECTANGLE, 0, myRaytraceOutputTexture->TextureId(), &anError);
- myRaytraceOutputImage = clCreateFromGLTexture2D (myComputeContext, CL_MEM_READ_WRITE,
- GL_TEXTURE_RECTANGLE, 0,
- myRaytraceOutputTexture[0], &anError);
if (anError != CL_SUCCESS)
{
#ifdef RAY_TRACE_PRINT_INFO
return Standard_False;
}
- myRaytraceOutputImageSmooth = clCreateFromGLTexture2D (myComputeContext, CL_MEM_READ_WRITE,
- GL_TEXTURE_RECTANGLE, 0,
- myRaytraceOutputTexture[1], &anError);
+ myRaytraceOutputImageAA = clCreateFromGLTexture2D (myComputeContext,
+ CL_MEM_READ_WRITE, GL_TEXTURE_RECTANGLE, 0, myRaytraceOutputTextureAA->TextureId(), &anError);
+
if (anError != CL_SUCCESS)
{
#ifdef RAY_TRACE_PRINT_INFO
Standard_Boolean OpenGl_Workspace::RunRaytraceOpenCLKernels (const Graphic3d_CView& theCView,
const GLfloat theOrigins[16],
const GLfloat theDirects[16],
- const int theSizeX,
- const int theSizeY)
+ const Standard_Integer theSizeX,
+ const Standard_Integer theSizeY)
{
if (myRaytraceRenderKernel == NULL || myRaytraceQueue == NULL)
return Standard_False;
anError = clSetKernelArg (myRaytraceSmoothKernel, anIndex++,
sizeof(cl_mem), &myRaytraceOutputImage);
anError |= clSetKernelArg (myRaytraceSmoothKernel, anIndex++,
- sizeof(cl_mem), &myRaytraceOutputImageSmooth);
+ sizeof(cl_mem), &myRaytraceOutputImageAA);
anError |= clSetKernelArg (myRaytraceSmoothKernel, anIndex++,
sizeof(cl_mem), &myRaytraceEnvironment);
anError |= clSetKernelArg (myRaytraceSmoothKernel, anIndex++,
det = T (1.0) / det;
- for (int i = 0; i < 16; ++i)
+ for (Standard_Integer i = 0; i < 16; ++i)
inv[i] *= det;
}
// purpose : Generates primary rays for corners of screen quad
// =======================================================================
void GenerateCornerRays (const GLdouble theInvModelProj[16],
- float theOrigins[16],
- float theDirects[16])
+ cl_float theOrigins[16],
+ cl_float theDirects[16])
{
- int aOriginIndex = 0;
- int aDirectIndex = 0;
+ Standard_Integer aOriginIndex = 0;
+ Standard_Integer aDirectIndex = 0;
- for (int y = -1; y <= 1; y += 2)
+ for (Standard_Integer y = -1; y <= 1; y += 2)
{
- for (int x = -1; x <= 1; x += 2)
+ for (Standard_Integer x = -1; x <= 1; x += 2)
{
OpenGl_RTVec4f aOrigin (float(x),
float(y),
1.f);
aOrigin = MatVecMult (theInvModelProj, aOrigin);
+ aOrigin.x() = aOrigin.x() / aOrigin.w();
+ aOrigin.y() = aOrigin.y() / aOrigin.w();
+ aOrigin.z() = aOrigin.z() / aOrigin.w();
+ aOrigin.w() = 1.f;
OpenGl_RTVec4f aDirect (float(x),
float(y),
1.f,
1.f);
- aDirect = MatVecMult (theInvModelProj, aDirect) - aOrigin;
+ aDirect = MatVecMult (theInvModelProj, aDirect);
+ aDirect.x() = aDirect.x() / aDirect.w();
+ aDirect.y() = aDirect.y() / aDirect.w();
+ aDirect.z() = aDirect.z() / aDirect.w();
+ aDirect.w() = 1.f;
+
+ aDirect = aDirect - aOrigin;
GLdouble aInvLen = 1.f / sqrt (aDirect.x() * aDirect.x() +
aDirect.y() * aDirect.y() +
// purpose : Redraws the window using OpenCL ray tracing
// =======================================================================
Standard_Boolean OpenGl_Workspace::Raytrace (const Graphic3d_CView& theCView,
- const int theSizeX,
- int theSizeY,
+ const Standard_Integer theSizeX,
+ const Standard_Integer theSizeY,
const Tint theToSwap)
{
if (!InitOpenCL())
TColStd_Array2OfReal theOrientation (0, 3, 0, 3);
TColStd_Array2OfReal theViewMapping (0, 3, 0, 3);
- myView->GetMatrices (theOrientation, theViewMapping, Standard_True);
+ myView->GetMatrices (theOrientation, theViewMapping);
GLdouble aOrientationMatrix[16];
GLdouble aViewMappingMatrix[16];
GLdouble aOrientationInvers[16];
- for (int j = 0; j < 4; ++j)
- for (int i = 0; i < 4; ++i)
+ for (Standard_Integer j = 0; j < 4; ++j)
+ for (Standard_Integer i = 0; i < 4; ++i)
{
aOrientationMatrix [4 * j + i] = theOrientation (i, j);
aViewMappingMatrix [4 * j + i] = theViewMapping (i, j);
aDirects);
// Compute ray-traced image using OpenCL kernel
- cl_mem anImages[] = { myRaytraceOutputImage, myRaytraceOutputImageSmooth };
+ cl_mem anImages[] = { myRaytraceOutputImage, myRaytraceOutputImageAA };
cl_int anError = clEnqueueAcquireGLObjects (myRaytraceQueue,
2, anImages,
0, NULL, NULL);
glColor3f (1.0f, 1.0f, 1.0f);
- glBindTexture (GL_TEXTURE_RECTANGLE, myRaytraceOutputTexture[theCView.IsAntialiasingEnabled ? 1 : 0]);
+ if (!theCView.IsAntialiasingEnabled)
+ myRaytraceOutputTexture->Bind (myGlContext);
+ else
+ myRaytraceOutputTextureAA->Bind (myGlContext);
if (myIsRaytraceDataValid)
{