blob: 734fabdd3aab6e3120f6ee080e5a2739f68fa5b6 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
2 * Copyright (C) 2009 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#ifndef ANDROID_RS_PROGRAM_VERTEX_H
18#define ANDROID_RS_PROGRAM_VERTEX_H
19
20#include "rsProgram.h"
21
22// ---------------------------------------------------------------------------
23namespace android {
24namespace renderscript {
25
Jason Samscfb1d112009-08-05 13:57:03 -070026class ProgramVertexState;
Jason Sams326e0dd2009-05-22 14:03:28 -070027
28class ProgramVertex : public Program
29{
30public:
Jason Samsb5909ce2009-07-21 12:20:54 -070031 const static uint32_t MAX_LIGHTS = 8;
Jason Sams326e0dd2009-05-22 14:03:28 -070032
Jason Sams4815c0d2009-12-15 12:58:36 -080033 ProgramVertex(Context *,const char * shaderText, uint32_t shaderLength,
34 const uint32_t * params, uint32_t paramLength);
35 ProgramVertex(Context *, bool texMat);
Jason Sams326e0dd2009-05-22 14:03:28 -070036 virtual ~ProgramVertex();
37
Jason Samsafcb25c2009-08-25 11:34:49 -070038 virtual void setupGL(const Context *rsc, ProgramVertexState *state);
Jason Samsc460e552009-11-25 13:22:07 -080039 virtual void setupGL2(const Context *rsc, ProgramVertexState *state, ShaderCache *sc);
Jason Sams326e0dd2009-05-22 14:03:28 -070040
41
Jason Sams326e0dd2009-05-22 14:03:28 -070042 void setTextureMatrixEnable(bool e) {mTextureMatrixEnable = e;}
Jason Samsb5909ce2009-07-21 12:20:54 -070043 void addLight(const Light *);
Jason Sams326e0dd2009-05-22 14:03:28 -070044
Jason Samsc9d43db2009-07-28 12:02:16 -070045 void setProjectionMatrix(const rsc_Matrix *) const;
46 void setModelviewMatrix(const rsc_Matrix *) const;
47 void setTextureMatrix(const rsc_Matrix *) const;
48
Jason Sams3a97c592009-09-30 17:36:20 -070049 void transformToScreen(const Context *, float *v4out, const float *v3in) const;
50
Jason Samsc460e552009-11-25 13:22:07 -080051 virtual void createShader();
Jason Samscd506532009-12-15 19:10:11 -080052 virtual void loadShader(Context *);
Jason Samsc460e552009-11-25 13:22:07 -080053 virtual void init(Context *);
54
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070055 virtual void serialize(OStream *stream) const;
56 virtual A3DClassID getClassId() const { return A3D_CLASS_ID_PROGRAM_VERTEX; }
57 static ProgramVertex *createFromStream(Context *rsc, IStream *stream);
Jason Sams3a97c592009-09-30 17:36:20 -070058
Jason Sams326e0dd2009-05-22 14:03:28 -070059protected:
Jason Samsb5909ce2009-07-21 12:20:54 -070060 uint32_t mLightCount;
Jason Samsb5909ce2009-07-21 12:20:54 -070061 ObjectBaseRef<const Light> mLights[MAX_LIGHTS];
62
Jason Sams326e0dd2009-05-22 14:03:28 -070063 // Hacks to create a program for now
64 bool mTextureMatrixEnable;
Jason Sams433eca32010-01-06 11:57:52 -080065
66private:
Jason Sams9ebb0c42010-01-12 12:12:28 -080067 void initAddUserElement(const Element *e, String8 *names, uint32_t *count, const char *prefix);
Jason Sams326e0dd2009-05-22 14:03:28 -070068};
69
70
Jason Samscfb1d112009-08-05 13:57:03 -070071class ProgramVertexState
Jason Sams326e0dd2009-05-22 14:03:28 -070072{
73public:
74 ProgramVertexState();
75 ~ProgramVertexState();
76
Jason Sams771565f2010-05-14 15:30:29 -070077 void init(Context *rsc);
Jason Samsf2649a92009-09-25 16:37:33 -070078 void deinit(Context *rsc);
Jason Sams771565f2010-05-14 15:30:29 -070079 void updateSize(Context *rsc);
Jason Sams8ce125b2009-06-17 16:52:59 -070080
81 ObjectBaseRef<ProgramVertex> mDefault;
Jason Samscfb1d112009-08-05 13:57:03 -070082 ObjectBaseRef<ProgramVertex> mLast;
Jason Sams8ce125b2009-06-17 16:52:59 -070083 ObjectBaseRef<Allocation> mDefaultAlloc;
Jason Samscfb1d112009-08-05 13:57:03 -070084
Jason Samsf2649a92009-09-25 16:37:33 -070085 ObjectBaseRef<Type> mAllocType;
Jason Sams8ce125b2009-06-17 16:52:59 -070086
Jason Sams326e0dd2009-05-22 14:03:28 -070087
Jason Samse9ed6cc2009-12-16 14:13:06 -080088 float color[4];
Jason Sams326e0dd2009-05-22 14:03:28 -070089};
90
91
92}
93}
94#endif
95
96