void ZoneManager::Render(const RenderOptions& renderOptions, const ViewFrustum3d& viewFrustum)
{
   bool bDrawBoundingBox = renderOptions.Get(RenderOptions::optionTerrainZoneBoundingBox);
   bool bUseFrustumCulling = renderOptions.Get(RenderOptions::optionTerrainFrustumCulling);

   m_indexBuffer.Bind();

   // call all blocks to render themselves
   for (size_t i=0, iMax=m_vecRenderData.size(); i<iMax; i++)
   {
      if (bUseFrustumCulling)
      {
         unsigned int xzone, yzone;
         IndexToZone(i, xzone, yzone);

         ATLASSERT(xzone < c_uiNumZones);
         ATLASSERT(yzone < c_uiNumZones);

         const AABox& box1 = m_vecRenderData[i].GetBoundingBox();
         AABox box2;
         box2.UpdateBound(Vector3d(xzone * m_uiZoneSize, 0.0, yzone * m_uiZoneSize) + box1.Min());
         box2.UpdateBound(Vector3d(xzone * m_uiZoneSize, 0.0, yzone * m_uiZoneSize) + box1.Max());

         // check if given quad is visible
         if (ViewFrustum3d::resultOutside == viewFrustum.IsBoxInside(box2))
            continue;
      }

      m_vecRenderData[i].Render(m_indexBuffer, bDrawBoundingBox);
   }

   m_indexBuffer.Unbind();
}
Exemple #2
0
QString HtmlTemplate::buildHtmlHeader(RenderOptions options) const
{
    QString header;

    // add javascript for scrollbar synchronization
    if (options.testFlag(Template::ScrollbarSynchronization)) {
        header += "<script type=\"text/javascript\">window.onscroll = function() { synchronizer.webViewScrolled(); }; </script>\n";
    }

    // add MathJax.js script to HTML header
    if (options.testFlag(Template::MathSupport)) {
        header += "<script type=\"text/javascript\" src=\"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML\"></script>\n";
    }

    // add Highlight.js script to HTML header
    if (options.testFlag(Template::CodeHighlighting)) {
        header += QString("<link rel=\"stylesheet\" href=\"qrc:/scripts/highlight.js/styles/%1.css\">\n").arg(codeHighlightingStyle());
        header += "<script src=\"qrc:/scripts/highlight.js/highlight.pack.js\"></script>\n";
        header += "<script>hljs.initHighlightingOnLoad();</script>\n";
    }

    // add mermaid.js script to HTML header
    if (options.testFlag(Template::DiagramSupport)) {
        header += "<script src=\"qrc:/scripts/mermaid/mermaid.full.min.js\"></script>\n";
    }

    return header;
}
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    RenderOptions w;
    w.show();

    return a.exec();
}
void ModelDisplayState::RenderAnimatedModelImmediateMode(RenderOptions& options) const
{
   AnimatedModel3d& model = *m_spModel->GetAnimated();
   const Data& data = model.GetData();

   AABox boundingBox;

   // now render all groups, using vertex and normals from joint render data
   for (const Group& group : data.m_vecGroups)
   {
      BindMaterial(group);

      glBegin(GL_TRIANGLES);

      for (size_t uiTriangleIndex : group.m_vecTriangleIndices)
      {
         ATLASSERT(uiTriangleIndex < data.m_vecTriangles.size());

         const Triangle& t = data.m_vecTriangles[uiTriangleIndex];
         for (unsigned int v=0; v<3; v++)
         {
            glTexCoord2fv(t.aTex[v].Data());

            size_t vertexIndex = t.auiVertexIndices[v];
            const Vertex& vert = data.m_vecVertices[vertexIndex];

            Vector3d vNormal = t.aNormals[v];
            model.TransformNormal(vert, m_vecJointRenderData, vNormal);

            glNormal3dv(vNormal.Data());

            Vector3d vVertex = vert.m_vPos;
            model.TransformVertex(vert, m_vecJointRenderData, vVertex);
            glVertex3dv(vVertex.Data());

            if (options.Get(RenderOptions::optionModelBoundingBox))
               boundingBox.UpdateBound(vVertex);
         }
      }

      glEnd();

      OpenGL::CountPolygons(group.m_vecTriangleIndices.size());

      if (options.Get(RenderOptions::optionModelNormals))
         RenderModelNormals(group);
   }

   if (options.Get(RenderOptions::optionModelBoundingBox))
      OpenGL::RenderBoundingBox(boundingBox.Min(), boundingBox.Max());
}
Exemple #5
0
QString HtmlTemplate::render(const QString &body, RenderOptions options) const
{
    // add scrollbar synchronization
    options |= Template::ScrollbarSynchronization;

    QString htmlBody(body);

    // Mermaid and highlighting.js don't work nicely together
    // So we need to replace the <code> section by a <div> section
    if (options.testFlag(Template::CodeHighlighting) && options.testFlag(Template::DiagramSupport)) {
        convertDiagramCodeSectionToDiv(htmlBody);
    }

    return renderAsHtml(QString(), htmlBody, options);
}
void ImposterManager::HandleEvent(Observable * observable)
{
	RenderOptions * renderOptions = dynamic_cast<RenderOptions*>(observable);
	if(renderOptions)
	{
		bool areImpostersEnabled = renderOptions->IsOptionEnabled(RenderOptions::IMPOSTERS_ENABLE);
		if(areImpostersEnabled)
		{
			CreateFBO();
		}
		else
		{
			ReleaseFBO();
		}
	}
}
void ModelDisplayState::RenderFrame(RenderOptions& options) const throw()
{
   // set front face to clockwise
   glPushAttrib(GL_POLYGON_BIT);
   glFrontFace(GL_CW);

   // enable backface culling
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);

   ATLASSERT(m_uiCurrentFrame < static_cast<unsigned int>(m_spModelData->m_iNumFrames));

   // render bounding box
   if (options.Get(RenderOptions::optionModelBoundingBox))
      RenderBoundingBox(m_uiCurrentFrame);

   m_spTexture->Bind();

   if (m_enRenderMode == renderDirect)
   {
      unsigned int uiPolycount = 0;
      RenderFramePercent(m_uiCurrentFrame, m_uiNextFrame, m_dPercentFrameDone, uiPolycount);

      OpenGL::CountPolygons(uiPolycount);
   }
   else
      if (m_enRenderMode == renderDisplayList ||
         m_enRenderMode == renderDisplayListOnDemandPrepare)
      {
      unsigned int uiStep = static_cast<unsigned int>(m_dPercentFrameDone * c_uiNumStepsPerFrame);
      if (uiStep >= c_uiNumStepsPerFrame)
         uiStep = c_uiNumStepsPerFrame - 1;

      unsigned int uiListIndex = m_uiCurrentFrame*c_uiNumStepsPerFrame + uiStep;

      if (m_enRenderMode == renderDisplayListOnDemandPrepare &&
         !m_spModelData->m_deqDisplayListPrepared[uiListIndex])
      {
         // prepare item
         const_cast<ModelDisplayState&>(*this).
            PrepareFrameStep(m_spModelData->m_frameDisplayLists, true, m_uiCurrentFrame, uiStep);

         m_spModelData->m_deqDisplayListPrepared[uiListIndex] = true;
      }
      else
      {
         // just call appropriate display list
         m_spModelData->m_frameDisplayLists.Call(uiListIndex);
      }

      OpenGL::CountPolygons(m_spModelData->m_uiDisplayListPolycount);
      }
      else
         ATLASSERT(false);

   glDisable(GL_TEXTURE_2D);

   glDisable(GL_CULL_FACE);
   glPopAttrib();
}
void ModelDisplayState::RenderAnimatedModelVertexBuffer(RenderOptions& options) const
{
   AnimatedModel3d& model = *m_spModel->GetAnimated();
   const Data& data = model.GetData();

   m_vbo.Bind();
   model.IndexBuffer().Bind();

   // render all groups
   for (size_t i=0, iMax=data.m_vecGroups.size(); i<iMax; i++)
   {
      const Group& group = data.m_vecGroups[i];

      BindMaterial(group);

      const GroupRenderData& renderData = model.GroupRenderDataVector()[i];

      model.IndexBuffer().RenderRange(renderData.m_range);

      OpenGL::CountPolygons(renderData.m_range.m_uiSize / 3);

      if (options.Get(RenderOptions::optionModelNormals))
         RenderModelNormals(group);
   }

   model.IndexBuffer().Unbind();
   m_vbo.Unbind();
}
void ModelRenderInstance::Render(RenderOptions& renderOptions)
{
   m_spDisplayState->Tick();

   OpenGL::PushedAttributes attrib(GL_POLYGON_BIT | GL_ENABLE_BIT | GL_CURRENT_BIT);

   if (renderOptions.Get(RenderOptions::optionModelFilled))
      glPolygonMode(GL_FRONT, GL_FILL);
   else
      glPolygonMode(GL_FRONT, GL_LINE);

   glPushMatrix();

   // position model
   Vector3d vPos = CalculatedPos();
   glTranslated(vPos.X(), vPos.Y(), vPos.Z());

   glRotated(m_dViewAngle, 0.0, 1.0, 0.0);

   double dTransparency = CalcPlayerTransparency();

   // blend model
   if (dTransparency < 1.0)
   {
      glEnable(GL_BLEND);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   }

   double dLuminance = m_bSelected ? 1.2 : 1.0;
   glColor4d(dLuminance, dLuminance, dLuminance, dTransparency);

   m_spDisplayState->Render(renderOptions);

   glPopMatrix();
}
void ModelDisplayState::Render(RenderOptions& options)
{
   if (options.Get(RenderOptions::optionModelJoints))
      OpenGL::RenderXyzAxes();

   if (!m_flagUploaded.IsSet())
      return;

   //RenderAnimatedModelImmediateMode(options);
   RenderAnimatedModelVertexBuffer(options);

   RenderStaticModels(options);

   // render joint lines and points
   if (options.Get(RenderOptions::optionModelJoints))
      RenderJoints();
}
void ModelDisplayState::RenderStaticModels(RenderOptions& options) const
{
   const std::vector<CompositeModel3d::StaticModelData>& vecStaticModels =
      m_spModel->StaticList();

   ATLASSERT(m_vecStaticModelTextures.size() == vecStaticModels.size());

   for (size_t i=0, iMax = vecStaticModels.size(); i<iMax; i++)
   {
      // enable model texture, if loaded
      if (m_vecStaticModelTextures[i] != NULL)
         m_vecStaticModelTextures[i]->Bind();

      // find mount point and matrix
      const CompositeModel3d::StaticModelData& data = vecStaticModels[i];

      ATLASSERT(data.m_iJointIndex >= 0);
      ATLASSERT(size_t(data.m_iJointIndex) < m_vecJointRenderData.size());

      size_t uiMountIndex = static_cast<size_t>(data.m_iJointIndex);

      Matrix4d matGlobal = m_vecJointRenderData[uiMountIndex].GlobalMatrix();
      matGlobal.Transpose();

      // transform current modelview matrix
      glPushMatrix();

      glMultMatrixd(matGlobal.Data());

      // render model
      data.m_spStatic->Render(options);

      // render mount point
      if (options.Get(RenderOptions::optionModelJoints))
         RenderMountPoint();

      glPopMatrix();
   }
}
Exemple #12
0
void MlEngine::fineOutput()
{
    ptime tt(second_clock::local_time());
    std::cout<<"fine output begins at "<<to_simple_string(tt)<<"\n";

    RenderOptions * opts = options();
    const int imageSizeX = opts->renderImageWidth();
    const int imageSizeY = opts->renderImageHeight();
    const int aas = opts->AASample();

#ifdef WIN32
    AiBegin();
    logArnoldVersion();
    loadPlugin("./driver_foo.dll");
    loadPlugin("./ExtendShaders.dll");
    loadPlugin("./mtoa_shaders.dll");

    const AtNodeEntry* nodeEntry = AiNodeEntryLookUp("featherUVCoord");
    if(nodeEntry == NULL) std::clog<<"\nWARNING: featherUVCoord node entry doesn't exist! Most likely ExtendShaders.dll is not loaded.\n";

    AtNode* options = AiNode("options");
    AtArray* outputs  = AiArrayAllocate(1, 1, AI_TYPE_STRING);
    AiArraySetStr(outputs, 0, "RGBA RGBA output:gaussian_filter output/foo");
    AiNodeSetArray(options, "outputs", outputs);

    AiNodeSetInt(options, "xres", imageSizeX);
    AiNodeSetInt(options, "yres", imageSizeY);
    AiNodeSetInt(options, "AA_samples", aas);
    AiNodeSetInt(options, "GI_diffuse_samples", 2);
    AiNodeSetInt(options, "auto_transparency_depth", 12);

    AtNode* driver = AiNode("driver_foo");
    AiNodeSetStr(driver, "name", "output/foo");

    AtNode * acamera = AiNode("persp_camera");
    AiNodeSetStr(acamera, "name", "/obj/cam");
    AiNodeSetFlt(acamera, "fov", camera()->fieldOfView());
    AiNodeSetFlt(acamera, "near_clip", camera()->nearClipPlane());
    AiNodeSetFlt(acamera, "far_clip", camera()->farClipPlane());

    AtMatrix matrix;
    setMatrix(camera()->fSpace, matrix);
    AiNodeSetMatrix(acamera, "matrix", matrix);

    AiNodeSetPtr(options, "camera", acamera);

    AtNode * filter = AiNode("gaussian_filter");
    AiNodeSetStr(filter, "name", "output:gaussian_filter");

    AtNode * standard = AiNode("standard");
    AiNodeSetStr(standard, "name", "/shop/standard1");
    AiNodeSetRGB(standard, "Kd_color", 1, 1, 1);

    AtNode * sphere = AiNode("sphere");
    AiNodeSetPtr(sphere, "shader", standard);
    AiNodeSetFlt(sphere, "radius", 1.f);
    AiM4Identity(matrix);
    matrix[3][0] = 0.f;
    matrix[3][1] = 0.f;
    matrix[3][2] = 50.f;
    AiNodeSetMatrix(sphere, "matrix", matrix);

    translateLights();
    translateCurves();

    logRenderError(AiRender(AI_RENDER_MODE_CAMERA));

    AiEnd();
#endif
    postRender();
}
Exemple #13
0
void MlEngine::testOutput()
{
    if(!m_barb) return;

    translateCurves();

    ptime tt(second_clock::local_time());
    std::cout<<"test output begins at "<<to_simple_string(tt)<<"\n";

    std::string ts("2002-01-20 23:59:59.000");
    ptime tref(time_from_string(ts));
    time_duration td = tt - tref;

    boost::this_thread::interruption_point();

    char dataPackage[PACKAGESIZE];

    try
    {
        boost::asio::io_service io_service;
        tcp::resolver resolver(io_service);
        tcp::resolver::query query(tcp::v4(), "localhost", "7879");
        tcp::resolver::iterator iterator = resolver.resolve(query);
        tcp::socket s(io_service);

        boost::asio::deadline_timer t(io_service);

        const int bucketSize = 64;
        RenderOptions * opts = options();
        const int imageSizeX = opts->renderImageWidth();
        const int imageSizeY = opts->renderImageHeight();

        for(int by = 0; by <= imageSizeY/bucketSize; by++) {
            if(by * bucketSize == imageSizeY) continue;
            for(int bx = 0; bx <= imageSizeX/bucketSize; bx++) {
                if(bx * bucketSize == imageSizeX) continue;
                int * rect = (int *)dataPackage;

                rect[2] = by * bucketSize;
                rect[3] = rect[2] + bucketSize - 1;
                if(rect[3] > imageSizeY - 1) rect[3] = imageSizeY - 1;

                rect[0] = bx * bucketSize;
                rect[1] = rect[0] + bucketSize - 1;
                if(rect[1] > imageSizeX - 1) rect[1] = imageSizeX - 1;

                const float grey = (float)((rand() + td.seconds() * 391) % 457) / 457.f;
                const unsigned npix = (rect[1] - rect[0] + 1) * (rect[3] - rect[2] + 1);
                int npackage = npix * 16 / PACKAGESIZE;
                if((npix * 16) % PACKAGESIZE > 0) npackage++;

                s.connect(*iterator);

                boost::asio::write(s, boost::asio::buffer(dataPackage, 16));
                //std::cout<<"sent    bucket("<<rect[0]<<","<<rect[1]<<","<<rect[2]<<","<<rect[3]<<")\n";

                boost::array<char, 32> buf;
                boost::system::error_code error;

                size_t reply_length = s.read_some(boost::asio::buffer(buf), error);

                float *color = (float *)dataPackage;
                for(int i = 0; i < PACKAGESIZE / 16; i++) {
                    color[i * 4] = color[i * 4 + 1] = color[i * 4 + 2] = grey;
                    color[i * 4 + 3] = 1.f;
                }

                for(int i=0; i < npackage; i++) {
                    boost::asio::write(s, boost::asio::buffer(dataPackage, PACKAGESIZE));
                    reply_length = s.read_some(boost::asio::buffer(buf), error);
                }

                boost::asio::write(s, boost::asio::buffer(dataPackage, 32));
                reply_length = s.read_some(boost::asio::buffer(buf), error);

                s.close();
                t.expires_from_now(boost::posix_time::seconds(1));
                t.wait();

                boost::this_thread::interruption_point();
            }
        }

    }
    catch (std::exception& e)
    {
        std::cerr << "Exception: " << e.what() << "\n";
    }
}
Exemple #14
0
void RenderLayer::Draw(const FastName & ownerRenderPass, Camera * camera, RenderLayerBatchArray * renderLayerBatchArray)
{
    TIME_PROFILE("RenderLayer::Draw");
    
    renderLayerBatchArray->Sort(camera);
    
#if CAN_INSTANCE_CHECK
    RenderBatch * prevBatch = 0;
    uint32 canBeInstanced = 0;
    
    Vector<int32> chain;
#endif
    uint32 size = (uint32)renderLayerBatchArray->GetRenderBatchCount();
    
    RenderOptions* options = RenderManager::Instance()->GetOptions();
    bool layerOcclustionStatsEnabled = options->IsOptionEnabled(RenderOptions::LAYER_OCCLUSION_STATS);
    
    if(layerOcclustionStatsEnabled)
    {
        if(NULL == occlusionQuery)
        {
            occlusionQuery = new OcclusionQuery();
            occlusionQuery->Init();
        }
    
        if(false == queryPending)
        {
            occlusionQuery->BeginQuery();
        }
    }
    
    for (uint32 k = 0; k < size; ++k)
    {
        RenderBatch * batch = renderLayerBatchArray->Get(k);

#if CAN_INSTANCE_CHECK
        if (prevBatch && batch->GetPolygonGroup() == prevBatch->GetPolygonGroup() && batch->GetMaterial()->GetParent() == prevBatch->GetMaterial()->GetParent())
        {
            canBeInstanced++;
        }else
        {
            if (canBeInstanced > 0)
                chain.push_back(canBeInstanced + 1);
            canBeInstanced = 0;
        }
#endif
        batch->Draw(ownerRenderPass, camera);
#if CAN_INSTANCE_CHECK
        prevBatch = batch;
#endif
    }
    
    if(layerOcclustionStatsEnabled)
    {
        if(false == queryPending)
        {
            occlusionQuery->EndQuery();
            queryPending = true;
        }
        
        if((true == queryPending) &&
           occlusionQuery->IsResultAvailable())
        {
            occlusionQuery->GetQuery(&lastFragmentsRenderedValue);
            queryPending = false;
        }
    }
    
#if CAN_INSTANCE_CHECK
    int32 realDrawEconomy = 0;
    for (uint32 k = 0; k < chain.size(); ++k)
    {
        realDrawEconomy += (chain[k] - 1);
    }
    
    Logger::Debug("Pass: %s Layer: %s Size: %d Can be instanced: %d Econ: %d", ownerRenderPass.c_str(), name.c_str(), size, chain.size(), realDrawEconomy);
    for (uint32 k = 0; k < chain.size(); ++k)
    {
        Logger::Debug("%d - %d", k, chain[k]);
    }
#endif
}
Exemple #15
0
//---------------------------------------------------------------------------------------
bool GmoBox::must_draw_bounds(RenderOptions& opt)
{
    return opt.must_draw_box_for( get_gmobj_type() );
}