~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to intern/cycles/kernel/osl/osl_services.cpp

  • Committer: Reinhard Tartler
  • Date: 2014-05-31 01:50:05 UTC
  • mfrom: (14.2.27 sid)
  • Revision ID: siretart@tauware.de-20140531015005-ml6druahuj82nsav
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include "kernel_camera.h"
45
45
#include "kernel_shader.h"
46
46
 
 
47
#ifdef WITH_PTEX
 
48
#include <Ptexture.h>
 
49
#endif
 
50
 
47
51
CCL_NAMESPACE_BEGIN
48
52
 
49
53
/* RenderServices implementation */
98
102
{
99
103
        kernel_globals = NULL;
100
104
        osl_ts = NULL;
 
105
 
 
106
#ifdef WITH_PTEX
 
107
        size_t maxmem = 16384 * 1024;
 
108
        ptex_cache = PtexCache::create(0, maxmem);
 
109
#endif
101
110
}
102
111
 
103
112
OSLRenderServices::~OSLRenderServices()
104
113
{
 
114
#ifdef WITH_PTEX
 
115
        ptex_cache->release();
 
116
#endif
105
117
}
106
118
 
107
119
void OSLRenderServices::thread_init(KernelGlobals *kernel_globals_, OSL::TextureSystem *osl_ts_)
498
510
        return false;
499
511
}
500
512
 
501
 
static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd, const OSLGlobals::Attribute& attr,
 
513
static bool set_attribute_matrix(const Transform& tfm, TypeDesc type, void *val)
 
514
{
 
515
        if(type == TypeDesc::TypeMatrix) {
 
516
                Transform transpose = transform_transpose(tfm);
 
517
                memcpy(val, &transpose, sizeof(Transform));
 
518
                return true;
 
519
        }
 
520
 
 
521
        return false;
 
522
}
 
523
 
 
524
static bool get_mesh_element_attribute(KernelGlobals *kg, const ShaderData *sd, const OSLGlobals::Attribute& attr,
502
525
                               const TypeDesc& type, bool derivatives, void *val)
503
526
{
504
527
        if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
505
 
            attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor)
506
 
        {
 
528
            attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
507
529
                float3 fval[3];
508
530
                fval[0] = primitive_attribute_float3(kg, sd, attr.elem, attr.offset,
509
531
                                                     (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
520
542
        }
521
543
}
522
544
 
 
545
static bool get_mesh_attribute(KernelGlobals *kg, const ShaderData *sd, const OSLGlobals::Attribute& attr,
 
546
                               const TypeDesc& type, bool derivatives, void *val)
 
547
{
 
548
        if (attr.type == TypeDesc::TypeMatrix) {
 
549
                Transform tfm = primitive_attribute_matrix(kg, sd, attr.offset);
 
550
                return set_attribute_matrix(tfm, type, val);
 
551
        }
 
552
        else {
 
553
                return false;
 
554
        }
 
555
}
 
556
 
523
557
static void get_object_attribute(const OSLGlobals::Attribute& attr, bool derivatives, void *val)
524
558
{
525
559
        size_t datasize = attr.value.datasize();
733
767
        if (it != attribute_map.end()) {
734
768
                const OSLGlobals::Attribute& attr = it->second;
735
769
 
736
 
                if (attr.elem != ATTR_ELEMENT_VALUE) {
 
770
                if (attr.elem != ATTR_ELEMENT_OBJECT) {
737
771
                        /* triangle and vertex attributes */
738
772
                        if (prim != ~0)
 
773
                                return get_mesh_element_attribute(kg, sd, attr, type, derivatives, val);
 
774
                        else
739
775
                                return get_mesh_attribute(kg, sd, attr, type, derivatives, val);
740
776
                }
741
777
                else {
776
812
        OSL::TextureSystem *ts = osl_ts;
777
813
        ShaderData *sd = (ShaderData *)(sg->renderstate);
778
814
        KernelGlobals *kg = sd->osl_globals;
 
815
 
 
816
#ifdef WITH_PTEX
 
817
        /* todo: this is just a quick hack, only works with particular files and options */
 
818
        if(string_endswith(filename.string(), ".ptx")) {
 
819
                float2 uv;
 
820
                int faceid;
 
821
 
 
822
                if(!primitive_ptex(kg, sd, &uv, &faceid))
 
823
                        return false;
 
824
 
 
825
                float u = uv.x;
 
826
                float v = uv.y;
 
827
                float dudx = 0.0f;
 
828
                float dvdx = 0.0f;
 
829
                float dudy = 0.0f;
 
830
                float dvdy = 0.0f;
 
831
 
 
832
                Ptex::String error;
 
833
                PtexPtr<PtexTexture> r(ptex_cache->get(filename.c_str(), error));
 
834
 
 
835
                if(!r) {
 
836
                        //std::cerr << error.c_str() << std::endl;
 
837
                        return false;
 
838
                }
 
839
 
 
840
                bool mipmaplerp = false;
 
841
                float sharpness = 1.0f;
 
842
                PtexFilter::Options opts(PtexFilter::f_bicubic, mipmaplerp, sharpness);
 
843
                PtexPtr<PtexFilter> f(PtexFilter::getFilter(r, opts));
 
844
 
 
845
                f->eval(result, options.firstchannel, options.nchannels, faceid, u, v, dudx, dvdx, dudy, dvdy);
 
846
 
 
847
                for(int c = r->numChannels(); c < options.nchannels; c++)
 
848
                        result[c] = result[0];
 
849
 
 
850
                return true;
 
851
        }
 
852
#endif
 
853
 
779
854
        OSLThreadData *tdata = kg->osl_tdata;
780
855
        OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
781
856
 
872
947
        return 0;
873
948
}
874
949
 
875
 
int OSLRenderServices::pointcloud_get(ustring filename, size_t *indices, int count,
 
950
int OSLRenderServices::pointcloud_get(OSL::ShaderGlobals *sg, ustring filename, size_t *indices, int count,
876
951
                                      ustring attr_name, TypeDesc attr_type, void *out_data)
877
952
{
878
953
        return 0;
879
954
}
880
955
 
 
956
bool OSLRenderServices::pointcloud_write(OSL::ShaderGlobals *sg,
 
957
                                         ustring filename, const OSL::Vec3 &pos,
 
958
                                         int nattribs, const ustring *names,
 
959
                                         const TypeDesc *types,
 
960
                                         const void **data)
 
961
{
 
962
        return false;
 
963
}
 
964
 
881
965
bool OSLRenderServices::trace(TraceOpt &options, OSL::ShaderGlobals *sg,
882
966
        const OSL::Vec3 &P, const OSL::Vec3 &dPdx,
883
967
        const OSL::Vec3 &dPdy, const OSL::Vec3 &R,
917
1001
        tracedata->ray = ray;
918
1002
        tracedata->setup = false;
919
1003
        tracedata->init = true;
 
1004
        tracedata->sd.osl_globals = sd->osl_globals;
920
1005
 
921
1006
        /* raytrace */
922
1007
#ifdef __HAIR__