blob: 502c5ee5903e91d8f786cc2c824d59b1c30fd74a [file] [log] [blame]
Alex Sakhartchouk4a36b452011-04-29 16:49:08 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18#include "rsdCore.h"
19#include "rsdProgramVertex.h"
20#include "rsdShader.h"
21#include "rsdShaderCache.h"
22
23#include "rsContext.h"
24#include "rsProgramVertex.h"
25#include "rsProgramFragment.h"
26
27#include <GLES/gl.h>
28#include <GLES/glext.h>
29#include <GLES2/gl2.h>
30#include <GLES2/gl2ext.h>
31
32using namespace android;
33using namespace android::renderscript;
34
35bool rsdProgramVertexInit(const Context *rsc, const ProgramVertex *pv,
36 const char* shader, uint32_t shaderLen) {
37 RsdShader *drv = new RsdShader(pv, GL_VERTEX_SHADER, shader, shaderLen);
38 pv->mHal.drv = drv;
39
40 return drv->createShader();
41}
42
43void rsdProgramVertexSetActive(const Context *rsc, const ProgramVertex *pv) {
44 RsdHal *dc = (RsdHal *)rsc->mHal.drv;
45
46 dc->gl.shaderCache->setActiveVertex((RsdShader*)pv->mHal.drv);
47}
48
49void rsdProgramVertexDestroy(const Context *rsc, const ProgramVertex *pv) {
50 RsdHal *dc = (RsdHal *)rsc->mHal.drv;
51
52 RsdShader *drv = NULL;
53 if(pv->mHal.drv) {
54 drv = (RsdShader*)pv->mHal.drv;
55 if (rsc->props.mLogShaders) {
56 LOGV("Destroying vertex shader with ID %u", drv->getShaderID());
57 }
58 if (drv->getShaderID()) {
59 dc->gl.shaderCache->cleanupVertex(drv->getShaderID());
60 }
61 delete drv;
62 }
63}
64
65bool rsdProgramFragmentInit(const Context *rsc, const ProgramFragment *pf,
66 const char* shader, uint32_t shaderLen) {
67 RsdShader *drv = new RsdShader(pf, GL_FRAGMENT_SHADER, shader, shaderLen);
68 pf->mHal.drv = drv;
69
70 return drv->createShader();
71}
72
73void rsdProgramFragmentSetActive(const Context *rsc, const ProgramFragment *pf) {
74 RsdHal *dc = (RsdHal *)rsc->mHal.drv;
75
76 dc->gl.shaderCache->setActiveFragment((RsdShader*)pf->mHal.drv);
77}
78
79void rsdProgramFragmentDestroy(const Context *rsc, const ProgramFragment *pf) {
80 RsdHal *dc = (RsdHal *)rsc->mHal.drv;
81
82 RsdShader *drv = NULL;
83 if(pf->mHal.drv) {
84 drv = (RsdShader*)pf->mHal.drv;
85 if (rsc->props.mLogShaders) {
86 LOGV("Destroying fragment shader with ID %u", drv->getShaderID());
87 }
88 if (drv->getShaderID()) {
89 dc->gl.shaderCache->cleanupFragment(drv->getShaderID());
90 }
91 delete drv;
92 }
93}
94
95