Example #1
0
/**
 * \brief Specify which varying should be written to the feedback stream(s)
 * \param prog a shader
 * \param n number of varyings
 * \param varyings names of the varyings that will be written onto the buffers
 * \param mode storage mode
 */
int SCE_RSetProgramFeedbackVaryings (SCE_RProgram *prog, SCEuint n,
                                     const char **varyings,
                                     SCE_RFeedbackStorageMode mode)
{
    size_t i;

    if (n == 0) {
        prog->fb_enabled = SCE_FALSE;
        for (i = 0; i < prog->n_varyings; i++)
            SCE_free (prog->fb_varyings[i]);
        SCE_free (prog->fb_varyings);
    } else {
        prog->n_varyings = n;
        if (!(prog->fb_varyings = SCE_malloc (n * sizeof *prog->fb_varyings)))
            goto fail;
        for (i = 0; i < n; i++)
            prog->fb_varyings[i] = NULL;
        for (i = 0; i < prog->n_varyings; i++) {
            if (!(prog->fb_varyings[i] = SCE_String_Dup (varyings[i])))
                goto fail;
        }
        prog->fb_enabled = SCE_TRUE;
        prog->fb_mode = mode;
        prog->linked = SCE_FALSE; /* link will be needed */
    }

    return SCE_OK;
fail:
    SCEE_LogSrc ();
    return SCE_ERROR;
}
Example #2
0
void SCE_RDeleteProgram (SCE_RProgram *prog)
{
    if (prog) {
        size_t i;
        if (glIsProgram (prog->id))
            glDeleteProgram (prog->id);
        for (i = 0; i < prog->n_varyings; i++)
            SCE_free (prog->fb_varyings[i]);
        SCE_free (prog->fb_varyings);
        SCE_free (prog);
    }
}
Example #3
0
/**
 * \brief Deletes an animated geometry
 */
void SCE_AnimGeom_Delete (SCE_SAnimatedGeometry *ageom)
{
    if (ageom) {
        size_t i;
        SCE_Geometry_Delete (ageom->geom);
        for (i = 0; i < SCE_MAX_ANIMATED_VERTEX_ATTRIBUTES; i++)
            SCE_free (ageom->base[i]);
        SCE_free (ageom->indices);
        if (ageom->canfree_baseskel)
            SCE_Skeleton_Delete (ageom->baseskel);
        if (ageom->canfree_animskel)
            SCE_Skeleton_Delete (ageom->animskel);
        SCE_free (ageom);
    }
}
Example #4
0
void SCE_VGrid_Delete (SCE_SVoxelGrid *vg)
{
    if (vg) {
        SCE_VGrid_Clear (vg);
        SCE_free (vg);
    }
}
Example #5
0
void SCE_VStore_Delete (SCE_SVoxelStorage *vs)
{
    if (vs) {
        SCE_VStore_Clear (vs);
        SCE_free (vs);
    }
}
Example #6
0
void SCE_TexData_Delete (SCE_STexData *d)
{
    if (d) {
        SCE_TexData_Clear (d);
        SCE_free (d);
    }
}
Example #7
0
void SCE_ParticleEmit_Delete (SCE_SParticleEmitter *emit)
{
    if (emit) {
        SCE_List_Remove (&emit->it);
        SCE_free (emit);
    }
}
Example #8
0
void SCE_VStore_Clear (SCE_SVoxelStorage *vs)
{
    int i;
    for (i = 0; i < SCE_MAX_VOXEL_STORAGE_LOD; i++)
        SCE_VStore_ClearLevel (&vs->levels[i]);
    SCE_free (vs->vacuum);
}
Example #9
0
int SCE_RBuildShaderGLSL (SCE_RShaderGLSL *shader)
{
    int compile_status = GL_TRUE;
    int loginfo_size = 0;
    char *loginfo = NULL;

    glShaderSource (shader->id, 1, (const GLchar**)&shader->data, NULL);
    glCompileShader (shader->id);

    glGetShaderiv (shader->id, GL_COMPILE_STATUS, &compile_status);
    if (compile_status != GL_TRUE) {
        SCEE_Log (SCE_INVALID_OPERATION);
        glGetShaderiv (shader->id, GL_INFO_LOG_LENGTH, &loginfo_size);
        loginfo = SCE_malloc (loginfo_size + 1);
        if (!loginfo) {
            SCEE_LogSrc ();
            return SCE_ERROR;
        }

        memset (loginfo, '\0', loginfo_size + 1);
        glGetShaderInfoLog (shader->id, loginfo_size, &loginfo_size, loginfo);

        SCEE_LogMsg ("error while compiling GLSL %s shader :\n%s",
                     sce_typename[shader->type], loginfo);
        SCE_free (loginfo);
        return SCE_ERROR;
    }

    shader->compiled = SCE_TRUE;
    return SCE_OK;
}
Example #10
0
SCE_RShaderGLSL* SCE_RCreateShaderGLSL (SCE_RShaderType type)
{
    SCE_RShaderGLSL *shader = NULL;

    shader = SCE_malloc (sizeof *shader);
    if (!shader) {
        SCEE_LogSrc ();
        return NULL;
    }

    shader->data = NULL;
    shader->compiled = SCE_FALSE;
    shader->type = type;
    shader->gltype = sce_gltype[type];

    shader->id = glCreateShader (shader->gltype);
    if (shader->id == 0) {
        SCEE_Log (SCE_ERROR);
        SCEE_LogMsg ("failed to create shader: %s", SCE_RGetError ());
        SCE_free (shader);
        return NULL;
    }

    return shader;
}
Example #11
0
/**
 * \brief Sets the vertices indices of an animated geometry
 * \sa SCE_AnimGeom_SetVertices(), SCE_Mesh_SetIndices()
 */
void SCE_AnimGeom_SetIndices (SCE_SAnimatedGeometry *ageom, size_t n,
                              SCEindices *indices, int canfree)
{
    if (ageom->canfree_indices)
        SCE_free (ageom->indices);
    ageom->indices = indices;
    ageom->n_indices = n;
}
Example #12
0
void SCE_RDeleteShaderGLSL (SCE_RShaderGLSL *shader)
{
    if (shader) {
        if (glIsShader (shader->id))
            glDeleteShader (shader->id);
        SCE_free (shader);
    }
}
Example #13
0
void SCE_TexData_Clear (SCE_STexData *d)
{
    SCE_List_Remove (&d->it);
    if (d->canfree && SCE_Resource_Free (d->img))
        SCE_Image_Delete (d->img);
    if (!d->data_user)
        SCE_free (d->data);
}
Example #14
0
/**
 * \brief Allocates memory for the base vertices (4D vectors)
 * \param attrib vertex attribute of the vectors
 * \param local are the vectors in local position from their joints?
 * \returns SCE_ERROR on error, SCE_OK otherwise
 */
int SCE_AnimGeom_AllocateBaseVertices (SCE_SAnimatedGeometry *ageom,
                                       SCE_EVertexAttribute attrib,
                                       int local)
{
    float *data = NULL;
    size_t i, n, id;
    if (local)
        n = ageom->n_weights;
    else
        n = ageom->n_vertices;
#ifdef SCE_DEBUG
    if (ageom->n_vertices == 0) {
        SCEE_Log (SCE_INVALID_OPERATION);
        SCEE_LogMsg ("you must call SCE_AnimGeom_AllocateVertices() "
                     "before calling this function");
        return SCE_ERROR;
    } else if (n == 0) {
        SCEE_Log (SCE_INVALID_OPERATION);
        SCEE_LogMsg ("you must call SCE_AnimGeom_AllocateWeights() "
                     "before calling this function");
        return SCE_ERROR;
    }
#endif
    id = SCE_AnimGeom_GetVerticesID (attrib);
    if (!(data = SCE_malloc (n * 4 * sizeof *data))) {
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    ageom->output[id] = SCE_malloc (ageom->n_vertices * 3 * sizeof *data);
    if (!ageom->output[id]) {
        SCE_free (data);
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    for (i = 0; i < n; i++) {
        data[i]     = ageom->output[id][i]     = 0.0f;
        data[i + 1] = ageom->output[id][i + 1] = 0.0f;
        data[i + 2] = ageom->output[id][i + 2] = 0.0f;
        data[i + 3] = 0.0f;
    }
    SCE_free (ageom->base[id]);
    ageom->base[id] = data;
    ageom->local[id] = local;
    return SCE_OK;
}
Example #15
0
/**
 * \brief Deletes a skybox
 */
void SCE_Skybox_Delete (SCE_SSkybox *skybox)
{
    if (skybox) {
        SCE_SceneEntity_DeleteInstance (skybox->instance);
        SCE_SceneEntity_Delete (skybox->entity);
        SCE_Mesh_Delete (skybox->mesh);
        SCE_free (skybox);
    }
}
Example #16
0
int SCE_RBuildProgram (SCE_RProgram *prog)
{
    const int modes[2] = {GL_INTERLEAVED_ATTRIBS, GL_SEPARATE_ATTRIBS};
    int status = GL_TRUE;
    int loginfo_size = 0;
    char *loginfo = NULL;
    int i, j;

    if (prog->linked)
        return SCE_OK;

    /* setting transform feedback up */
    if (prog->fb_enabled) {
        glTransformFeedbackVaryings (prog->id, prog->n_varyings,
                                     (const GLchar**)prog->fb_varyings,
                                     modes[prog->fb_mode]);
    }

    /* TODO: follows the same pattern as SCE_RSetDrawBuffers */
    j = 0;
    for (i = 0; i < SCE_MAX_ATTACHMENT_BUFFERS; i++) {
        if (*prog->outputs[i])
            glBindFragDataLocation (prog->id, j++, prog->outputs[i]);
    }

    glLinkProgram (prog->id);

    glGetProgramiv (prog->id, GL_LINK_STATUS, &status);
    if (status != GL_TRUE) {
        SCEE_Log (SCE_INVALID_OPERATION);

        glGetProgramiv (prog->id, GL_INFO_LOG_LENGTH, &loginfo_size);
        loginfo = SCE_malloc (loginfo_size + 1);
        if (!loginfo) {
            SCEE_LogSrc ();
            return SCE_ERROR;
        }
        memset (loginfo, '\0', loginfo_size + 1);
        glGetProgramInfoLog (prog->id, loginfo_size, &loginfo_size, loginfo);

        /* TODO: add program name */
        SCEE_LogMsg ("can't link program, reason: %s", loginfo);

        SCE_free (loginfo);
        return SCE_ERROR;
    }

    prog->linked = SCE_TRUE;

    /* if the map was previously built, rebuild it */
    if (prog->map_built)
        SCE_RSetupProgramAttributesMapping (prog);

    return SCE_OK;
}
Example #17
0
/**
 * \brief Allocates memory for vertices
 * \returns SCE_ERROR on error, SCE_OK otherwise
 * \sa SCE_AnimGeom_AllocateWeights()
 */
int SCE_AnimGeom_AllocateVertices (SCE_SAnimatedGeometry *ageom, size_t n)
{
    size_t i;
    SCE_free (ageom->vertices);
    if (!(ageom->vertices = SCE_malloc (n * sizeof *ageom->vertices))) {
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    ageom->n_vertices = n;
    for (i = 0; i < n; i++)
        SCE_AnimGeom_InitVertex (&ageom->vertices[i]);
    return SCE_OK;
}
Example #18
0
/**
 * \brief Allocates memory for vertex weights
 * \returns SCE_ERROR on error, SCE_OK otherwise
 * \sa SCE_AnimGeom_SetWeights(), SCE_AnimGeom_AllocateVertices()
 */
int SCE_AnimGeom_AllocateWeights (SCE_SAnimatedGeometry *ageom, size_t n)
{
    size_t i;
    SCE_free (ageom->weights);
    if (!(ageom->weights = SCE_malloc (n * sizeof *ageom->weights))) {
        SCEE_LogSrc ();
        return SCE_ERROR;
    }
    ageom->n_weights = n;
    for (i = 0; i < n; i++)
        SCE_AnimGeom_InitWeight (&ageom->weights[i]);
    return SCE_OK;
}
Example #19
0
/**
 * \brief Creates a new animated geometry
 */
SCE_SAnimatedGeometry* SCE_AnimGeom_Create (void)
{
    SCE_SAnimatedGeometry *ageom = NULL;
    if (!(ageom = SCE_malloc (sizeof *ageom)))
        SCEE_LogSrc ();
    else {
        SCE_AnimGeom_Init (ageom);
        if (!(ageom->geom = SCE_Geometry_Create ())) {
            SCE_free (ageom), ageom = NULL;
            SCEE_LogSrc ();
        }
    }
    return ageom;
}
Example #20
0
/**
 * \brief Set the vertices in global position
 * \param bpose the bind pose skeleton
 * \sa SCE_AnimGeom_SetGlobal()
 * \todo manage the w component
 */
int SCE_AnimGeom_SetGlobal (SCE_SAnimatedGeometry *ageom)
{
    size_t i;

    for (i = 0; i < SCE_MAX_ANIMATED_VERTEX_ATTRIBUTES; i++) {
        if (ageom->local[i] && ageom->base[i]) {
            SCEvertices *vert = NULL;
            size_t j;
            /* alloc new base */
            if (!(vert = SCE_malloc (ageom->n_vertices * 4 * sizeof *vert))) {
                SCEE_LogSrc ();
                return SCE_ERROR;
            }
            SCE_AnimGeom_ApplySkeletonLocal (ageom, i, ageom->baseskel);
            for (j = 0; j < ageom->n_vertices; j++) {
                SCE_Vector3_Copy (&vert[j * 4], &ageom->output[i][j * 3]);
            }
            SCE_free (ageom->base[i]);
            ageom->base[i] = vert;
            ageom->local[i] = SCE_FALSE;
        }
    }
    return SCE_OK;
}
Example #21
0
void SCE_VGrid_Clear (SCE_SVoxelGrid *vg)
{
    SCE_free (vg->data);
}
Example #22
0
static void SCE_VStore_ClearLevel (SCE_SVoxelStorageLevel *sl)
{
    SCE_free (sl->data);
}
Example #23
0
void SCE_RDeleteMaterial (SCE_RMaterial *mat)
{
    SCE_free (mat);
}
Example #24
0
void SCE_RDeleteLight (SCE_RLight *light)
{
    SCE_free (light);
}
Example #25
0
void SCE_RDeletePointSprite (SCE_RPointSprite *point)
{
    SCE_free (point);
}